Esempio n. 1
0
void BenderControlConnectionHandler::messageReceived (const MemoryBlock &message)
{
	if (message.getSize() <= 2)
		return;

	BenderControlMessageType type = getControlMessageType (message);

	switch (type)
	{
		case helo:
			respondToHelo(message);
			return;

		case streamData:
			respondToStreamDataRequest(message);
			return;

		case setMotor:
			respondToSetMotorRequest(message);
			return;

		default:
			_DBG("\tunknown message received ["+message.toString()+"]");
			break;
	}
}
Esempio n. 2
0
bool ResourceFile::isResourceFile (const File& file)
{
    if (file.hasFileExtension ("cpp;cc;h"))
    {
        ScopedPointer <InputStream> in (file.createInputStream());

        if (in != nullptr)
        {
            MemoryBlock mb;
            in->readIntoMemoryBlock (mb, 256);
            return mb.toString().contains (resourceFileIdentifierString);
        }
    }

    return false;
}
void FileLogger::trimFileSize (int maxFileSizeBytes) const
{
    if (maxFileSizeBytes <= 0)
    {
        logFile.deleteFile();
    }
    else
    {
        const int64 fileSize = logFile.getSize();

        if (fileSize > maxFileSizeBytes)
        {
            ScopedPointer <FileInputStream> in (logFile.createInputStream());
            jassert (in != nullptr);

            if (in != nullptr)
            {
                in->setPosition (fileSize - maxFileSizeBytes);
                String content;

                {
                    MemoryBlock contentToSave;
                    contentToSave.setSize ((size_t) maxFileSizeBytes + 4);
                    contentToSave.fillWith (0);

                    in->read (contentToSave.getData(), maxFileSizeBytes);
                    in = nullptr;

                    content = contentToSave.toString();
                }

                int newStart = 0;

                while (newStart < fileSize
                        && content[newStart] != '\n'
                        && content[newStart] != '\r')
                    ++newStart;

                logFile.deleteFile();
                logFile.appendText (content.substring (newStart), false, false);
            }
        }
    }
}
                void initialise(const String& commandLineParameters)
                {
					Logger::writeToLog("CTRLR:initialise params \""+commandLineParameters+"\"");

					SystemStats::setApplicationCrashHandler (&CtrlrApplication::crashHandler);

					if (!commandLineParameters.isEmpty())
					{
						String stackTrace = "?";
						StringArray parameters		= getParameters(commandLineParameters);
						StringArray parameterValues	= getParameterValues(commandLineParameters);

						if (parameters.contains("crashReport"))
						{
							File crashReportForExec(parameterValues[parameters.indexOf("crashReport")]);
							File crashReportFile(crashReportForExec.withFileExtension(crashReportForExec.getFileExtension()+".crash"));
							AlertWindow crashReport("Ctrlr has crashed", "This is a crash indicator, it means that Ctrlr has crashed for some reason. Some crash information will be written to: "+crashReportFile.getFullPathName(), AlertWindow::WarningIcon);

							if (parameters.contains("stackTrace"))
							{
								if (!parameterValues[parameters.indexOf("stackTrace")].isEmpty())
								{
									MemoryBlock mb;
									mb.fromBase64Encoding(parameterValues[parameters.indexOf("stackTrace")]);
									stackTrace = mb.toString();
									crashReport.addTextBlock (stackTrace);
								}
							}
							crashReport.addButton ("OK", 1, KeyPress (KeyPress::returnKey));
							crashReport.runModalLoop();

							crashReportFile.replaceWithText ("Ctrlr crash at: "+Time::getCurrentTime().toString(true, true, true, true) + "\nStack trace:\n"+stackTrace);

							JUCEApplication::quit();
						}
					}


					filterWindow = new CtrlrStandaloneWindow (ProjectInfo::projectName + String("/") + ProjectInfo::versionString, Colours::lightgrey);

					if (File::isAbsolutePath(commandLineParameters.unquoted()))
						filterWindow->openFileFromCli (File(commandLineParameters.unquoted()));
                }
Esempio n. 5
0
    //==============================================================================
    static XmlElement decryptXML (String hexData, RSAKey rsaPublicKey)
    {
        BigInteger val;
        val.parseString (hexData, 16);

        RSAKey key (rsaPublicKey);
        jassert (key.isValid());

        ScopedPointer<XmlElement> xml;

        if (! val.isZero())
        {
            key.applyToValue (val);

            const MemoryBlock mb (val.toMemoryBlock());

            if (CharPointer_UTF8::isValidString (static_cast<const char*> (mb.getData()), (int) mb.getSize()))
                xml = XmlDocument::parse (mb.toString());
        }

        return xml != nullptr ? *xml : XmlElement("key");
    }
 void messageReceived (const MemoryBlock& message)
 {
     owner.appendMessage ("Connection #" + String (ourNumber) + " - message received: " + message.toString());
 }
Esempio n. 7
0
    //==============================================================================
    AiffAudioFormatReader (InputStream* in)
        : AudioFormatReader (in, TRANS (aiffFormatName))
    {
        using namespace AiffFileHelpers;

        if (input->readInt() == chunkName ("FORM"))
        {
            const int len = input->readIntBigEndian();
            const int64 end = input->getPosition() + len;

            const int nextType = input->readInt();
            if (nextType == chunkName ("AIFF") || nextType == chunkName ("AIFC"))
            {
                bool hasGotVer = false;
                bool hasGotData = false;
                bool hasGotType = false;

                while (input->getPosition() < end)
                {
                    const int type = input->readInt();
                    const uint32 length = (uint32) input->readIntBigEndian();
                    const int64 chunkEnd = input->getPosition() + length;

                    if (type == chunkName ("FVER"))
                    {
                        hasGotVer = true;

                        const int ver = input->readIntBigEndian();
                        if (ver != 0 && ver != (int) 0xa2805140)
                            break;
                    }
                    else if (type == chunkName ("COMM"))
                    {
                        hasGotType = true;

                        numChannels = (unsigned int) input->readShortBigEndian();
                        lengthInSamples = input->readIntBigEndian();
                        bitsPerSample = input->readShortBigEndian();
                        bytesPerFrame = (numChannels * bitsPerSample) >> 3;

                        unsigned char sampleRateBytes[10];
                        input->read (sampleRateBytes, 10);
                        const int byte0 = sampleRateBytes[0];

                        if ((byte0 & 0x80) != 0
                                || byte0 <= 0x3F || byte0 > 0x40
                                || (byte0 == 0x40 && sampleRateBytes[1] > 0x1C))
                            break;

                        unsigned int sampRate = ByteOrder::bigEndianInt (sampleRateBytes + 2);
                        sampRate >>= (16414 - ByteOrder::bigEndianShort (sampleRateBytes));
                        sampleRate = (int) sampRate;

                        if (length <= 18)
                        {
                            // some types don't have a chunk large enough to include a compression
                            // type, so assume it's just big-endian pcm
                            littleEndian = false;
                        }
                        else
                        {
                            const int compType = input->readInt();

                            if (compType == chunkName ("NONE") || compType == chunkName ("twos"))
                            {
                                littleEndian = false;
                            }
                            else if (compType == chunkName ("sowt"))
                            {
                                littleEndian = true;
                            }
                            else
                            {
                                sampleRate = 0;
                                break;
                            }
                        }
                    }
                    else if (type == chunkName ("SSND"))
                    {
                        hasGotData = true;

                        const int offset = input->readIntBigEndian();
                        dataChunkStart = input->getPosition() + 4 + offset;
                        lengthInSamples = (bytesPerFrame > 0) ? jmin (lengthInSamples, (int64) (length / bytesPerFrame)) : 0;
                    }
                    else if (type == chunkName ("MARK"))
                    {
                        const uint16 numCues = (uint16) input->readShortBigEndian();

                        // these two are always the same for AIFF-read files
                        metadataValues.set ("NumCuePoints", String (numCues));
                        metadataValues.set ("NumCueLabels", String (numCues));

                        for (uint16 i = 0; i < numCues; ++i)
                        {
                            uint16 identifier = (uint16) input->readShortBigEndian();
                            uint32 offset = (uint32) input->readIntBigEndian();
                            uint8 stringLength = (uint8) input->readByte();
                            MemoryBlock textBlock;
                            input->readIntoMemoryBlock (textBlock, stringLength);

                            // if the stringLength is even then read one more byte as the
                            // string needs to be an even number of bytes INCLUDING the
                            // leading length character in the pascal string
                            if ((stringLength & 1) == 0)
                                input->readByte();

                            const String prefixCue ("Cue" + String (i));
                            metadataValues.set (prefixCue + "Identifier", String (identifier));
                            metadataValues.set (prefixCue + "Offset", String (offset));

                            const String prefixLabel ("CueLabel" + String (i));
                            metadataValues.set (prefixLabel + "Identifier", String (identifier));
                            metadataValues.set (prefixLabel + "Text", textBlock.toString());
                        }
                    }
                    else if (type == chunkName ("COMT"))
                    {
                        const uint16 numNotes = (uint16) input->readShortBigEndian();
                        metadataValues.set ("NumCueNotes", String (numNotes));

                        for (uint16 i = 0; i < numNotes; ++i)
                        {
                            uint32 timestamp = (uint32) input->readIntBigEndian();
                            uint16 identifier = (uint16) input->readShortBigEndian(); // may be zero in this case
                            uint16 stringLength = (uint16) input->readShortBigEndian();

                            MemoryBlock textBlock;
                            input->readIntoMemoryBlock (textBlock, stringLength + (stringLength & 1));

                            const String prefix ("CueNote" + String (i));
                            metadataValues.set (prefix + "TimeStamp", String (timestamp));
                            metadataValues.set (prefix + "Identifier", String (identifier));
                            metadataValues.set (prefix + "Text", textBlock.toString());
                        }
                    }
                    else if (type == chunkName ("INST"))
                    {
                        HeapBlock <InstChunk> inst;
                        inst.calloc (jmax ((size_t) length + 1, sizeof (InstChunk)), 1);
                        input->read (inst, length);
                        inst->copyTo (metadataValues);
                    }
                    else if ((hasGotVer && hasGotData && hasGotType)
                             || chunkEnd < input->getPosition()
                             || input->isExhausted())
                    {
                        break;
                    }

                    input->setPosition (chunkEnd);
                }
Esempio n. 8
0
void NetworkConnection::ClientConnection::messageReceived (const MemoryBlock & message)
{
    // When some data is received : Do something using Owner

	/*String fileName=message.toString();
	String fileExtention=*/
     
	if(isFirstCall)
		{
		
			if(messageProtocols.isFirstTimeName(message.toString(), clientInfo.clientName))
			{
				firstTimeNameHandle();
			}
			else if(messageProtocols.isConnectTimeName(message.toString(), clientInfo.clientName))
			{
				connectTimeNameHandle();
			}
			isFirstCall = false;
			return;
		}
		String dataToSend, otherdataToSend;
		// Now it has to be normal connection and communicate after first connection time
		if(messageProtocols.isAcquireLockMessage(message.toString()))
		{
			if(ownerControlBarComponent->manageServerLock(true))
			{
				clientInfo.hasLock = true;
				dataToSend = messageProtocols.constructAllowLock();
				ownerControlBarComponent->getClientListComponent()->setClientHasLock(clientInfo);
				ownerServer.sendOtherThatServerIslocked(true, clientInfo.clientName);
				// Send info to clientListComponent also...
			}
			else
			{
				clientInfo.hasLock = false;
				dataToSend = messageProtocols.constructDenyLock();
				// No need to send data to clientListComp...
			}
			MemoryBlock messageData(dataToSend.toUTF8(), dataToSend.getNumBytesAsUTF8());
			sendMessage(messageData);
			if(clientInfo.hasLock)
			{
				int index;
				if(ownerControlBarComponent->getPlayerComponent()->isCurrentlyPlaying(index))
				{
					dataToSend = messageProtocols.constructPlayingIndex(String(index));
					MemoryBlock messageData(dataToSend.toUTF8(), dataToSend.getNumBytesAsUTF8());
					sendMessage(messageData);
				}
			}
		}
		else if(messageProtocols.isReleaseLockMessage(message.toString()))
		{
			ownerControlBarComponent->manageServerLock(false);
			clientInfo.hasLock = false;
			ownerControlBarComponent->getClientListComponent()->setClientHasLock(clientInfo);
			ownerServer.sendOtherThatServerIslocked(false);
		}
		// Only check for these messages when client has lock
		else if(clientInfo.hasLock)
		{
			if(messageProtocols.isPlayMessage(message.toString()))
			{
				ownerControlBarComponent->getPlayerComponent()->playPauseButtonClicked();
			}
			else if(messageProtocols.isPlayAfterStopMessage(message.toString(), dataToSend))
			{
				ownerControlBarComponent->getPlayListComponent()->songPlayedByClick(dataToSend.getIntValue());
			}
			else if(messageProtocols.isPauseMessage(message.toString()))
			{
				ownerControlBarComponent->getPlayerComponent()->playPauseButtonClicked();
			}
			else if(messageProtocols.isStopMessage(message.toString()))
			{
				ownerControlBarComponent->getPlayerComponent()->signalThreadShouldExit();
				ownerControlBarComponent->getPlayerComponent()->stopButtonClicked();
			}
			else if(messageProtocols.isBackMessage(message.toString()))
			{
				ownerControlBarComponent->getPlayerComponent()->backButtonClicked();
			}
			else if(messageProtocols.isNextMessage(message.toString()))
			{
				ownerControlBarComponent->getPlayerComponent()->nextButtonClicked();
			}
			else if(messageProtocols.isAddInPlayList(message.toString(), dataToSend))
			{
				ownerControlBarComponent->getPlayListComponent()->addInPlayListFromClient(dataToSend);
				ownerServer.sendAddInPlayList(dataToSend, clientInfo.clientIpAddress);
			}
			else if(messageProtocols.isDropInPlayList(message.toString(), dataToSend, otherdataToSend))
			{
				ownerControlBarComponent->getPlayListComponent()->dropInPlayListFromClient(dataToSend, otherdataToSend.getIntValue());
				ownerServer.sendDropInPlayList(dataToSend, otherdataToSend.getIntValue(), clientInfo.clientIpAddress);
			}
			else if(messageProtocols.isdragDropPlayListMessage (message.toString(), dataToSend, otherdataToSend))
			{
				ownerControlBarComponent->getPlayListComponent()->itemDroppedFromClient(dataToSend, otherdataToSend);
				ownerServer.sendDragDropIndex (dataToSend, otherdataToSend, clientInfo.clientIpAddress);
			}
			else if(message.toString().contains(messageProtocols.getDeleteInPlayListID()))
			{
				Array<int> tempIndexList;
				messageProtocols.isDeleteInPlayList(message.toString(), tempIndexList);
				ownerControlBarComponent->getPlayListComponent()->deleteInPlayListFromClient(tempIndexList);
				ownerServer.sendDeleteInPlayList(tempIndexList, clientInfo.clientIpAddress);
			}
			else  if(message.toString().contains(".")) //if message contain file name of media...
			{
				if(message.toString().contains("localFileExistAtServer")) //if file already exist at server
				{
					localFileName=message.toString().fromLastOccurrenceOf(",",false,false);
					StringArray  fileArray;
			   	    fileArray.insert(0,File::getCurrentWorkingDirectory().getFullPathName() + File::separatorString + "temp" + File::separatorString + localFileName);
				    ownerControlBarComponent->getPlayListComponent()->filesDropped(fileArray,X,Y);
				}

				else if(message.toString().contains("localFileNonExistAtServer")) 
				{
					localFileName=message.toString().fromLastOccurrenceOf(",",false,false);
				}
				else
				{

					localFileName=message.toString().upToFirstOccurrenceOf(",",false,false);
					String temp=message.toString().fromFirstOccurrenceOf(",",false,false);
					String x=temp.upToFirstOccurrenceOf(",",false,false);
					String y=temp.fromFirstOccurrenceOf(",",false,false).upToLastOccurrenceOf(",",false,false);
					String filePath=temp.fromLastOccurrenceOf(",",false,false);
					X=x.getIntValue();
					Y=y.getIntValue(); 
					String command;

					File tempFile(File::getCurrentWorkingDirectory().getFullPathName() + File::separatorString + "temp"+ File::separatorString + localFileName );
					if(tempFile.exists())
					{
						command=filePath +",FileExist,"+"true";
						//String fileNameMessage=fileName;
					}
					else
					{
						command=filePath+",FileExist,"+"false";
					}
						MemoryBlock message(command.toUTF8(),command.getNumBytesAsUTF8());
						sendMessage(message);
				}
			}
			else //save recevied file in temp folder and add file in media list. 
			{						
				File temp(File::getCurrentWorkingDirectory().getFullPathName() + File::separatorString + "temp" );
				temp.createDirectory();
			    File tempSong(File::getCurrentWorkingDirectory().getFullPathName() + File::separatorString + "temp" + File::separatorString + localFileName);					
				tempSong.appendData(message.getData(),message.getSize());
				StringArray  fileArray;
			   	fileArray.insert(0,tempSong.getFullPathName());
				ownerControlBarComponent->getPlayListComponent()->filesDropped(fileArray,X,Y);
			}
		}
}