Exemplo n.º 1
0
int HttpConnection::request(const char* data, OutputStream& response, bool log_request)
{         
    int requestStatus = 0;

    StringBuffer dataString(data);
    BufferInputStream bufferStream(dataString);
          
    requestStatus = request(bufferStream, response, log_request);
          
    return requestStatus;
}  
Exemplo n.º 2
0
void QCodesysNVTelegram::initializeTelegram(void)
{
    if(length<20)
    {
        data.resize(length);
    }
    else
    {
        data.resize(length);
    }
        QByteArray buffer;
        QDataStream bufferStream(identity);
        quint32 identityInt;
        bufferStream >> identityInt;


        QCodesysNVConvert<quint32>::convertToBytes(buffer, QCodesysNVType::DWORD, identityInt);
        data.replace(0,4,buffer);

        buffer.clear();
        QCodesysNVConvert<quint32>::convertToBytes(buffer, QCodesysNVType::DWORD, id);
        data.replace(4,4,buffer);

        buffer.clear();
        QCodesysNVConvert<quint16>::convertToBytes(buffer, QCodesysNVType::WORD, cob_id);
        data.replace(8,2,buffer);

        buffer.clear();
        QCodesysNVConvert<quint16>::convertToBytes(buffer, QCodesysNVType::WORD, subindex);
        data.replace(10,2,buffer);

        buffer.clear();
        QCodesysNVConvert<quint16>::convertToBytes(buffer, QCodesysNVType::WORD, items);
        data.replace(12,2,buffer);

        buffer.clear();
        QCodesysNVConvert<quint16>::convertToBytes(buffer, QCodesysNVType::WORD, length);
        data.replace(14,2,buffer);

        buffer.clear();
        QCodesysNVConvert<quint16>::convertToBytes(buffer, QCodesysNVType::WORD, counter);
        data.replace(16,2,buffer);

        buffer.clear();
        QCodesysNVConvert<quint8>::convertToBytes(buffer, QCodesysNVType::BYTE, flags);
        data.replace(18,1,buffer);

        buffer.clear();
        QCodesysNVConvert<quint8>::convertToBytes(buffer, QCodesysNVType::BYTE, checksum);
        data.replace(19,1,buffer);


}
Exemplo n.º 3
0
StringVector &split(const std::string &haystack, const char delimiter, bool ignoreEmpty = false) {
	std::stringstream bufferStream(haystack);
	std::string findBuffer;
	StringVector *finds = new StringVector();

	while(std::getline(bufferStream, findBuffer, delimiter))
	{
		if(!ignoreEmpty || findBuffer.length() > 0)		//Don´t add if empty and ignoreEmpty is set
			finds->push_back(findBuffer);
	}
	return *finds;
}
Exemplo n.º 4
0
void QmlProfilerTraceFile::loadQzt(QIODevice *device)
{
    QDataStream stream(device);
    stream.setVersion(QDataStream::Qt_5_5);

    QByteArray magic;
    stream >> magic;
    if (magic != QByteArray("QMLPROFILER")) {
        fail(tr("Invalid magic: %1").arg(QLatin1String(magic)));
        return;
    }

    qint32 dataStreamVersion;
    stream >> dataStreamVersion;

    if (dataStreamVersion > QDataStream::Qt_DefaultCompiledVersion) {
        fail(tr("Unknown data stream version: %1").arg(dataStreamVersion));
        return;
    }
    stream.setVersion(dataStreamVersion);

    qint64 traceStart, traceEnd;
    stream >> traceStart >> traceEnd;
    setTraceStart(traceStart);
    setTraceEnd(traceEnd);

    QBuffer buffer;
    QDataStream bufferStream(&buffer);
    bufferStream.setVersion(dataStreamVersion);
    QByteArray data;
    setDeviceProgress(device);

    QmlProfilerModelManager *manager = modelManager();
    if (!isCanceled()) {
        stream >> data;
        buffer.setData(qUncompress(data));
        buffer.open(QIODevice::ReadOnly);
        quint32 numEventTypes;
        bufferStream >> numEventTypes;
        if (numEventTypes > quint32(std::numeric_limits<int>::max())) {
            fail(tr("Excessive number of event types: %1").arg(numEventTypes));
            return;
        }

        for (int typeId = 0; typeId < static_cast<int>(numEventTypes); ++typeId) {
            QmlEventType type;
            bufferStream >> type;
            manager->setEventType(typeId, std::move(type));
        }
        buffer.close();
        setDeviceProgress(device);
    }
Exemplo n.º 5
0
    void loadRegion(std::istream &in)
    {
        FileUtils::streamRead(in, _locationTable.get(), 4096);
        FileUtils::streamRead(in, _timestampTable.get(), 4096);

        std::memset(_regionGrid.get(), 0, 512*256*512*sizeof(ElementType));
        std::memset(_biomes.get(), 0xFF, 512*512*sizeof(uint8));
        _regionHeight = 0;

        for (int i = 0; i < 1024; ++i) {
            int chunkX = i % 32;
            int chunkZ = i / 32;

            uint32 offset = 4*1024*(
                (uint32(_locationTable[i*4 + 0]) << 16) +
                (uint32(_locationTable[i*4 + 1]) <<  8) +
                 uint32(_locationTable[i*4 + 2]));
            uint32 length = uint32(_locationTable[i*4 + 3])*4*1024;

            if (offset == 0 || length == 0)
                continue;

            in.seekg(offset);
            FileUtils::streamRead(in, _compressedChunk.get(), length);

            uint32 chunkLength =
                (uint32(_compressedChunk[0]) << 24) +
                (uint32(_compressedChunk[1]) << 16) +
                (uint32(_compressedChunk[2]) <<  8) +
                 uint32(_compressedChunk[3]);
            if (_compressedChunk[4] != 2) {
                // Only accept Zlib compression
                tfm::printf("Ignoring chunk %i, %i with unsupported compression mode %i\n", chunkX, chunkZ, _compressedChunk[4]);
                std::cout.flush();
                continue;
            }

            uLongf destLength = DecompressedChunkSize;
            if (uncompress(_decompressedChunk.get(), &destLength, _compressedChunk.get() + 5, chunkLength) != Z_OK) {
                tfm::printf("Decompression failed for chunk %i, %i\n", chunkX, chunkZ);
                std::cout.flush();
                continue;
            }

            MemBuf buffer(reinterpret_cast<char *>(_decompressedChunk.get()), destLength);
            std::istream bufferStream(&buffer);

            loadChunk(bufferStream, i % 32, i/32);
        }
    }
Exemplo n.º 6
0
bool MeshData::loadFromFile(const tstring& filePath)
{
	BUFFER_DATA bufferData;
	if (!FileUtil::readFile(bufferData, filePath)) return false;

	tstring baseDir = StringUtil::getFileDir(filePath);

	BufferStream bufferStream(bufferData);
	if (parseMeshFile(&bufferStream, baseDir))
	{
		setId(filePath);
		return true;
	}

	return false;
}
Exemplo n.º 7
0
void POP3Message::fetch(ref <POP3Folder> msgFolder, const int options)
{
	ref <POP3Folder> folder = m_folder.acquire();

	if (folder != msgFolder)
		throw exceptions::folder_not_found();

	// FETCH_STRUCTURE and FETCH_FLAGS are not supported by POP3.
	if (options & (folder::FETCH_STRUCTURE | folder::FETCH_FLAGS))
		throw exceptions::operation_not_supported();

	// Check for the real need to fetch the full header
	static const int optionsRequiringHeader =
		folder::FETCH_ENVELOPE | folder::FETCH_CONTENT_INFO |
		folder::FETCH_FULL_HEADER | folder::FETCH_IMPORTANCE;

	if (!(options & optionsRequiringHeader))
		return;

	// No need to differenciate between FETCH_ENVELOPE,
	// FETCH_CONTENT_INFO, ... since POP3 only permits to
	// retrieve the whole header and not fields in particular.

	// Emit the "TOP" command
	std::ostringstream oss;
	oss << "TOP " << m_num << " 0";

	ref <POP3Store> store = folder->m_store.acquire();

	store->sendRequest(oss.str());

	try
	{
		string buffer;
		utility::outputStreamStringAdapter bufferStream(buffer);

		POP3Response::readLargeResponse(store->m_socket, store->m_timeoutHandler,
			bufferStream, /* progress */ NULL, /* predictedSize */ 0);

		m_header = vmime::create <header>();
		m_header->parse(buffer);
	}
	catch (exceptions::command_error& e)
	{
		throw exceptions::command_error("TOP", e.response());
	}
}
Exemplo n.º 8
0
void POP3Message::fetch(shared_ptr <POP3Folder> msgFolder, const fetchAttributes& options)
{
	shared_ptr <POP3Folder> folder = m_folder.lock();

	if (folder != msgFolder)
		throw exceptions::folder_not_found();

	// STRUCTURE and FLAGS attributes are not supported by POP3
	if (options.has(fetchAttributes::STRUCTURE | fetchAttributes::FLAGS))
		throw exceptions::operation_not_supported();

	// Check for the real need to fetch the full header
	static const int optionsRequiringHeader =
		fetchAttributes::ENVELOPE | fetchAttributes::CONTENT_INFO |
		fetchAttributes::FULL_HEADER | fetchAttributes::IMPORTANCE;

	if (!options.has(optionsRequiringHeader))
		return;

	// No need to differenciate between ENVELOPE, CONTENT_INFO, ...
	// since POP3 only permits to retrieve the whole header and not
	// fields in particular.

	// Emit the "TOP" command
	shared_ptr <POP3Store> store = folder->m_store.lock();

	POP3Command::TOP(m_num, 0)->send(store->getConnection());

	try
	{
		string buffer;
		utility::outputStreamStringAdapter bufferStream(buffer);

		POP3Response::readLargeResponse(store->getConnection(),
			bufferStream, /* progress */ NULL, /* predictedSize */ 0);

		m_header = make_shared <header>();
		m_header->parse(buffer);
	}
	catch (exceptions::command_error& e)
	{
		throw exceptions::command_error("TOP", e.response());
	}
}
Exemplo n.º 9
0
int MeshLoader::loadOBJ(string path)
{
    _mesh = new Mesh();

    string aux;

    ifstream ifs(path.c_str());
    string buffer;

    Vertex center;
    center.x = 0.0;
    center.y = 0.0;
    center.z = 0.0;


    ifs.open(path.c_str());
    ifs.clear();

    if (!ifs.is_open())
    {
        return -1;
    }



    string id, ind1, ind2, ind3, temp;
    double dato1, dato2, dato3;

    while (!ifs.eof())
    {
        getline(ifs, buffer);
        istringstream bufferStream(buffer);

        aux = buffer.substr(0,2);
        if (aux == "v ")
        {
            bufferStream >> id >> dato1 >> dato2 >> dato3;
            _mesh->addVertex(dato1, dato2, dato3);

            center.x += dato1;
            center.y += dato2;
            center.z += dato3;
        } else if (aux == "f ")
Exemplo n.º 10
0
//////////////////////////////////////////////////////////////////////
// name Get Functions
//////////////////////////////////////////////////////////////////////
// Load the binary rep
GLC_3DRep GLC_BSRep::loadRep()
{
	GLC_3DRep loadedRep;

	if (open(QIODevice::ReadOnly))
	{
		if (headerIsOk())
		{
			timeStampOk(QDateTime());
			GLC_BoundingBox boundingBox;
			m_DataStream >> boundingBox;
			bool useCompression;
			m_DataStream >> useCompression;
			if (useCompression)
			{
				QByteArray CompresseBuffer;
				m_DataStream >> CompresseBuffer;
				QByteArray uncompressedBuffer= qUncompress(CompresseBuffer);
				uncompressedBuffer.squeeze();
				CompresseBuffer.clear();
				CompresseBuffer.squeeze();
				QDataStream bufferStream(uncompressedBuffer);
				bufferStream >> loadedRep;
			}
			else
			{
				m_DataStream >> loadedRep;
			}
			loadedRep.setFileName(m_FileInfo.filePath());

			if (!close())
			{
				QString message(QString("GLC_BSRep::loadRep An error occur when loading file ") + m_FileInfo.fileName());
				GLC_FileFormatException fileFormatException(message, m_FileInfo.fileName(), GLC_FileFormatException::WrongFileFormat);
				throw(fileFormatException);
			}
		}
		else
		{
Exemplo n.º 11
0
bool QmlProfilerFileReader::loadQzt(QIODevice *device)
{
    QDataStream stream(device);
    stream.setVersion(QDataStream::Qt_5_5);

    QByteArray magic;
    stream >> magic;
    if (magic != QByteArray("QMLPROFILER")) {
        emit error(tr("Invalid magic: %1").arg(QLatin1String(magic)));
        return false;
    }

    qint32 dataStreamVersion;
    stream >> dataStreamVersion;

    if (dataStreamVersion > QDataStream::Qt_DefaultCompiledVersion) {
        emit error(tr("Unknown data stream version: %1").arg(dataStreamVersion));
        return false;
    }
    stream.setVersion(dataStreamVersion);

    stream >> m_traceStart >> m_traceEnd;

    QBuffer buffer;
    QDataStream bufferStream(&buffer);
    bufferStream.setVersion(dataStreamVersion);
    QByteArray data;
    updateProgress(device);

    stream >> data;
    buffer.setData(qUncompress(data));
    buffer.open(QIODevice::ReadOnly);
    bufferStream >> m_eventTypes;
    buffer.close();
    emit typesLoaded(m_eventTypes);
    updateProgress(device);

    stream >> data;
    buffer.setData(qUncompress(data));
    buffer.open(QIODevice::ReadOnly);
    bufferStream >> m_notes;
    buffer.close();
    emit notesLoaded(m_notes);
    updateProgress(device);

    const int eventBufferLength = 1024;
    QVector<QmlEvent> eventBuffer(eventBufferLength);
    int eventBufferIndex = 0;
    while (!stream.atEnd()) {
        stream >> data;
        buffer.setData(qUncompress(data));
        buffer.open(QIODevice::ReadOnly);
        while (!buffer.atEnd()) {
            if (isCanceled())
                return false;
            QmlEvent &event = eventBuffer[eventBufferIndex];
            bufferStream >> event;
            if (bufferStream.status() == QDataStream::Ok) {
                if (event.typeIndex() >= m_eventTypes.length()) {
                    emit error(tr("Invalid type index %1").arg(event.typeIndex()));
                    return false;
                }
                m_loadedFeatures |= (1ULL << m_eventTypes[event.typeIndex()].feature());
            } else if (bufferStream.status() == QDataStream::ReadPastEnd) {
                break; // Apparently EOF is a character so we end up here after the last event.
            } else if (bufferStream.status() == QDataStream::ReadCorruptData) {
                emit error(tr("Corrupt data before position %1.").arg(device->pos()));
                return false;
            } else {
                Q_UNREACHABLE();
            }
            if (++eventBufferIndex == eventBufferLength) {
                emit qmlEventsLoaded(eventBuffer);
                eventBufferIndex = 0;
            }
        }
        buffer.close();
        updateProgress(device);
    }
    eventBuffer.resize(eventBufferIndex);
    emit qmlEventsLoaded(eventBuffer);
    emit success();
    return true;
}
Exemplo n.º 12
0
int eMoviePlayer::playStream(eString mrl)
{
	int apid = -1, vpid = -1, ac3 = -1;
	
	// receive video stream from VLC on PC
	eDebug("[MOVIEPLAYER] start playing stream...");

	status.BUFFERFILLED = false;
	pthread_mutex_lock(&mutex);
	tsBuffer.clear();
	pthread_mutex_unlock(&mutex);

	if (requestStream() < 0)
	{
		eDebug("[MOVIEPLAYER] requesting stream failed...");
		close(fd);
		return -1;
	}
	int ibuff;
	if(status.PLG)
		ibuff = initialBuffer;
	else
		ibuff = INITIALBUFFER;
	
	if (bufferStream(fd, ibuff) == 0)
	{
		eDebug("[MOVIEPLAYER] buffer is empty.");
		close(fd);
		if (cancelBuffering > 0)
			return 0;
		else
			return -4;
	}
	
	status.BUFFERFILLED = true;
	
	find_avpids(&tsBuffer, &vpid, &apid, &ac3);
	if (vpid == -1 || apid == -1)
	{
		if(status.NSF ) // plugin can playback file without A or V too
		{
			eDebug("[MOVIEPLAYER] both AV pids not found: vpid %d apid %d, but play.",vpid,apid);
		}
		else
		{
			eDebug("[MOVIEPLAYER] no AV pids found.");
			close(fd);
			return -5;
		}
	}
	status.NSF=false;

	status.AVPIDS_FOUND = true;

	if(!status.DVB)
		stopDVB();

	Decoder::setMpegDevice(-1);
	// set pids
	Decoder::parms.vpid = vpid;
	Decoder::parms.apid = apid;
	Decoder::parms.audio_type = DECODE_AUDIO_MPEG;
	
	int ac3default = 0;
	eConfig::getInstance()->getKey("/elitedvb/audio/ac3default", ac3default);
	if (ac3 && ac3default)
	{
		if (mrl.right(3) == "vob" || mrl.left(3) == "dvd")
			Decoder::parms.audio_type = DECODE_AUDIO_AC3_VOB;
		else
			Decoder::parms.audio_type = DECODE_AUDIO_AC3;
	}

	eZapMain::getInstance()->hideInfobar();
	usleep(100000);
	Decoder::SetStreamType(TYPE_PES);
	Decoder::Set();

#ifndef DISABLE_LCD
	unsigned int pos = mrl.find_last_of('/');
	eZapLCD::getInstance()->lcdMain->ServiceName->setText(mrl.right(mrl.size() - pos - 1));
#endif

	createThreads();
	
	status.ACTIVE = true;
	
	return 0;
}