void GdbRemoteServerEngine::callTargetRemote()
{
    QByteArray rawChannel = runParameters().remoteChannel.toLatin1();
    QByteArray channel = rawChannel;

    // Don't touch channels with explicitly set protocols.
    if (!channel.startsWith("tcp:") && !channel.startsWith("udp:")
            && !channel.startsWith("file:") && channel.contains(':')
            && !channel.startsWith('|'))
    {
        // "Fix" the IPv6 case with host names without '['...']'
        if (!channel.startsWith('[') && channel.count(':') >= 2) {
            channel.insert(0, '[');
            channel.insert(channel.lastIndexOf(':'), ']');
        }
        channel = "tcp:" + channel;
    }

    if (m_isQnxGdb)
        postCommand("target qnx " + channel, NoFlags, CB(handleTargetQnx));
    else if (runParameters().multiProcess)
        postCommand("target extended-remote " + channel, NoFlags, CB(handleTargetExtendedRemote));
    else
        postCommand("target remote " + channel, NoFlags, CB(handleTargetRemote));
}
void GdbRemoteServerEngine::callTargetRemote()
{
    //m_breakHandler->clearBreakMarkers();

    // "target remote" does three things:
    //     (1) connects to the gdb server
    //     (2) starts the remote application
    //     (3) stops the remote application (early, e.g. in the dynamic linker)
    QByteArray channel = startParameters().remoteChannel.toLatin1();

    // Don't touch channels with explicitly set protocols.
    if (!channel.startsWith("tcp:") && !channel.startsWith("udp:")
            && !channel.startsWith("file:") && channel.contains(':'))
    {
        // "Fix" the IPv6 case with host names without '['...']'
        if (!channel.startsWith('[') && channel.count(':') >= 2) {
            channel.insert(0, '[');
            channel.insert(channel.lastIndexOf(':'), ']');
        }
        channel = "tcp:" + channel;
    }

    if (m_isQnxGdb)
        postCommand("target qnx " + channel, CB(handleTargetQnx));
    else
        postCommand("target remote " + channel, CB(handleTargetRemote));
}
// convert MAC from hex string to binary
// e.g. 00:11:22:dd:ee:ff -> 6-byte array
QByteArray SettingDbus::macHex2Bin(const QByteArray &hexMac)
{
    const int MAC_STR_LEN = 17;
    QByteArray ba = hexMac;

    if (ba.isEmpty()) {
        return ba;
    }

    // Check the MAC first and correct it.
    // Although fromHex() ignores invalid characters, it scans the array from
    // the end; so add missing zeroes to have even number of characters.
    for (int i = 0; i < MAC_STR_LEN; i++) {
        char ch = i < ba.size() ? ba.at(i) : ':';
        int mod = i%3;
        if (mod != 2) {
            if (ch == ':') ba.insert(i-mod, "0");
            else if (!isxdigit(ch)) ba[i] = '0';
        } else {
            if (ch != ':') ba.insert(i, ":");
        }
    }
    ba.resize(MAC_STR_LEN);

    return QByteArray::fromHex(ba);
}
示例#4
0
QByteArray WebSocketWorker::CreateFrame(WebSocketFrame::OpCode type,
                                        const QByteArray &payload)
{
    QByteArray frame;

    int payloadSize = payload.length();

    if (payloadSize >= qPow(2,64))
    {
        LOG(VB_GENERAL, LOG_ERR, "WebSocketWorker::CreateFrame() - Payload "
                              "exceeds the allowed size for a single frame");
        return frame;
    }

    if (type >= 0x08)
    {
        //if (!finalFrame)
        //   SendClose(kCloseProtocolError, "Control frames MUST NOT be fragmented");
        if (payloadSize > 125)
        {
            LOG(VB_GENERAL, LOG_ERR, "WebSocketWorker::CreateFrame() - Control frames MUST NOT have payload greater than 125bytes");
            return frame;
        }
    }

    uint16_t header = 0;
    uint16_t extendedHeader = 0; // For payloads > 125 bytes
    uint64_t superHeader = 0; // For payloads > 65,535 bytes

    // Only support single frames for now
    header |= (1 << 15); // FIN (1 bit)
    // RSV 1 to RSV 3 (1 bit each)
    header |= (type << 8); // OpCode (4 bits)
    header |= (0 << 7); // Mask (1 bit) (Off)
    if (payloadSize < 126)
    {
        header |= payloadSize;
        frame.insert(2, payload.constData(), payloadSize);
    }
    else if (payloadSize <= 65535)
    {
        header |= 126;
        extendedHeader = payloadSize;
        frame.insert(4, payload.constData(), payloadSize);
    }
    else
    {
        header |= 127;
        superHeader = payloadSize;
        frame.insert(10, payload.constData(), payloadSize);
    }

    frame[0] = (uint8_t)((header >> 8) & 0xFF);
    frame[1] = (uint8_t)(header & 0xFF);
    if (extendedHeader > 0)
    {
        frame[2] = (extendedHeader >> 8) & 0xFF;
        frame[3] = extendedHeader & 0xFF;
    }
示例#5
0
void UmlClass::addAssign(bool cte)
{
    TRACE_FUNCTION;
    UmlOperation * op = UmlOperation::create(this, "operator=");

    if (op == 0)
        UmlCom::trace("can't add assignment contructor");
    else {
        // add 'source' parameter

        UmlParameter param;

        param.name = "source";
        param.dir = (cte) ? InputDirection : InputOutputDirection;
        param.type.type = this;

        op->addParameter(0, param);

        // set return type, add the parameter profile

        UmlTypeSpec t;

        t.type = this;

        op->set_ReturnType(t);

        QByteArray p = (cte) ? "const ${t0} & ${p0}" : "${t0} & ${p0}";
        QByteArray s;
        int index;

        s = op->cppDecl();

        if (s.isEmpty())
            s = CppSettings::operationDecl();

        if ((index = s.indexOf("${(}")) != -1)
            s.insert(index + 4, (const char *)p); //[rageek] cast because QByteArray

        if ((index = s.indexOf("${type}")) != -1)
            s.insert(index + 7, " &");

        op->set_CppDecl(s);

        s = op->cppDef();

        if (s.isEmpty())
            s = CppSettings::operationDef();

        if ((index = s.indexOf("${(}")) != -1)
            s.insert(index + 4, (const char *)p); //[rageek] cast because QByteArray

        if ((index = s.indexOf("${type}")) != -1)
            s.insert(index + 7, " &");

        op->set_CppDef(s);
    }
}
示例#6
0
void UmlClass::addCopy(bool cte)
{
    TRACE_FUNCTION;
    UmlOperation * op = UmlOperation::create(this, name());

    if (op == 0)
        UmlCom::trace("can't add copy contructor");
    else {
        // to see that it is a copy constructor
        op->set_Stereotype("copy");

        // add 'source' parameter

        UmlParameter param;

        param.name = "source";
        param.dir = (cte) ? InputDirection : InputOutputDirection;
        param.type.type = this;

        op->addParameter(0, param);

        // add the parameter profile, and
        // remove the useless "${type} " mainly to remove the space

        QByteArray p = (cte) ? "const ${t0} & ${p0}" : "${t0} & ${p0}";
        QByteArray s;
        int index;

        s = op->cppDecl();

        if (s.isEmpty())
            s = CppSettings::operationDecl();

        if ((index = s.indexOf("${(}")) != -1)
            s.insert(index + 4, (const char *)p); //[rageek] cast because QByteArray

        if ((index = s.indexOf("${type} ")) != -1)
            s.remove(index, 8);

        op->set_CppDecl(s);

        s = op->cppDef();

        if (s.isEmpty())
            s = CppSettings::operationDef();

        if ((index = s.indexOf("${(}")) != -1)
            s.insert(index + 4, (const char *)p); //[rageek] cast because QByteArray

        if ((index = s.indexOf("${type} ")) != -1)
            s.remove(index, 8);

        op->set_CppDef(s);
    }
}
// Add extra text in case of the empty line or the line starting with ')'.
// Track such extra pieces of text in isInsideModifiedLine().
int forceIndentWithExtraText(QByteArray &buffer, const QTextBlock &block, bool secondTry)
{
    const QString blockText = block.text();
    int firstNonWhitespace = Utils::indexOf(blockText,
                                            [](const QChar &ch) { return !ch.isSpace(); });
    int utf8Offset = Utils::Text::utf8NthLineOffset(block.document(),
                                                    buffer,
                                                    block.blockNumber() + 1);
    if (firstNonWhitespace > 0)
        utf8Offset += firstNonWhitespace;
    else
        utf8Offset += blockText.length();

    const bool closingParenBlock = firstNonWhitespace >= 0
                                   && blockText.at(firstNonWhitespace) == ')';

    int extraLength = 0;
    if (firstNonWhitespace < 0 || closingParenBlock) {
        //This extra text works for the most cases.
        QByteArray dummyText("a;a;");

        // Search for previous character
        QTextBlock prevBlock = block.previous();
        bool prevBlockIsEmpty = prevBlock.position() > 0 && prevBlock.text().trimmed().isEmpty();
        while (prevBlockIsEmpty) {
            prevBlock = prevBlock.previous();
            prevBlockIsEmpty = prevBlock.position() > 0 && prevBlock.text().trimmed().isEmpty();
        }
        if (closingParenBlock || prevBlock.text().endsWith(','))
            dummyText = "&& a";

        buffer.insert(utf8Offset, dummyText);
        extraLength += dummyText.length();
    }

    if (secondTry) {
        int nextLinePos = buffer.indexOf('\n', utf8Offset);
        if (nextLinePos < 0)
            nextLinePos = buffer.size() - 1;

        if (nextLinePos > 0) {
            // If first try was not successful try to put ')' in the end of the line to close possibly
            // unclosed parentheses.
            // TODO: Does it help to add different endings depending on the context?
            buffer.insert(nextLinePos, ')');
            extraLength += 1;
        }
    }

    return extraLength;
}
void Output_Thread::Send(QByteArray out_data)//посылка данных
{
    //реализовать добавление 0 после D7 в теле протокола
    quint8 i,j=3;
    //---------------------------------------------------
    while((out_data.indexOf((char)0xD7,j))!=-1)
    {
        i=out_data.indexOf((char)0xD7,j);
        out_data.insert(i+1,(char)0x0);
        j=i+1;
         qDebug() << "D7 DETECTED";
    }
    //---------------------------------------------------

    if(port->isOpen())
    {
        data=out_data;
        qint64 snd=port->write(data.data(),data.size());
        qDebug() << "Write is : " << out_data.size() << " bytes";
        if(snd==data.size())
        {
            emit Send_OK(true);//передан весь буфер
        }
        else
        {
           emit Send_OK(false);//передан не весь буфер
        }
    }
    else
    {
        emit Send_OK(false);//порт был закрыт
    }
    usleep(2000);
}
示例#9
0
QByteArray CDataFrame::formatOutputDataStream()
{
    QByteArray  d;

    //***填充数据帧
    int size = _data.size();
    d.insert(0,_DLE_BYTE_);
    d.insert(1,_STX_BYTE_);
    d.insert(2,_command);
    d.insert(3,_data);
    d.insert(3+size,_crc);
    d.insert(4+size,_DLE_BYTE_);
    d.insert(5+size,_ETX_BYTE_);

    return d;
}
QByteArray BtClient::translateBtKeyEvent(QByteArray base)
{
    char length[1];
    length[0] = (char) base.size();
    base.insert(0, length, 1);
    return base;
}
示例#11
0
QString fingerprintify(const QByteArray &ba) {
  const QByteArray &baHex = ba.toHex();
  QByteArray result = baHex;
  for (int i = baHex.size() - 2; i > 0; i -= 2)
    result.insert(i, ':');
  return result;
}
示例#12
0
void HttpWindow::upload(QString _file) {

	this->uploadFlag = true;
	QString bound;
	QString crlf;
	QString data;
	QByteArray dataToSend;

	QFile file(_file);
	file.open(QIODevice::ReadOnly);

	bound = "---------------------------7d935033608e2";
	crlf = 0x0d;
	crlf += 0x0a;
	data = "--" + bound + crlf
			+ "Content-Disposition: form-data; name=\"uploaded_file\"; ";
	data += "filename=\"" + file.fileName() + "\"";
	data += crlf + "Content-Type: application/octet-stream" + crlf + crlf;
	dataToSend.insert(0, data);
	dataToSend.append(file.readAll());
	dataToSend.append(crlf + "--" + bound + "--" + crlf);

	//QUrl url(THE_REPO->getUrl() + "test.php");
	QUrl url(THE_REPO->getUrl() + "uploader_FantaCalcGui.php");
	QNetworkRequest * req = new QNetworkRequest();
	req->setUrl(url);
	req->setHeader(QNetworkRequest::ContentTypeHeader,
			"multipart/form-data; boundary=" + bound);
	file.close();

	progressDialog->setLabelText(
			tr("Uploading %1.").arg(QFileInfo(file).fileName()));

	reply = qnam.post(*req, dataToSend);
}
示例#13
0
void Ffmpeg::saveSoundTrack(TSoundTrack *st) {
  m_sampleRate    = st->getSampleRate();
  m_channelCount  = st->getChannelCount();
  m_bitsPerSample = st->getBitPerSample();
  // LONG count = st->getSampleCount();
  int bufSize         = st->getSampleCount() * st->getSampleSize();
  const UCHAR *buffer = st->getRawData();

  m_audioPath = getFfmpegCache().getQString() + "//" +
                QString::fromStdString(m_path.getName()) + "tempOut.raw";
  m_audioFormat = "s" + QString::number(m_bitsPerSample);
  if (m_bitsPerSample > 8) m_audioFormat = m_audioFormat + "le";
  std::string strPath                    = m_audioPath.toStdString();

  QByteArray data;
  data.insert(0, (char *)buffer, bufSize);

  QFile file(m_audioPath);
  file.open(QIODevice::WriteOnly);
  file.write(data);
  file.close();
  m_hasSoundTrack = true;

  m_audioArgs << "-f";
  m_audioArgs << m_audioFormat;
  m_audioArgs << "-ar";
  m_audioArgs << QString::number(m_sampleRate);
  m_audioArgs << "-ac";
  m_audioArgs << QString::number(m_channelCount);
  m_audioArgs << "-i";
  m_audioArgs << m_audioPath;

  // add file to framesWritten for cleanup
  m_cleanUpList.push_back(m_audioPath);
}
示例#14
0
void FileSender::connected(void)
{
	QByteArray data = id.toLocal8Bit();
	data.insert(0, "FILE");	// insert indicator that this socket handles file transfer
	//	send an id message and then wait for a START message 
	//	from receiver, which will trigger readyRead signal
	socket->write(data);
}
void TcpClient::sendTestResultToServer(const StudentResult &result)
{
    //create msg string
    QString studentResult = result.testName
            + divSymbol
            + result.firstName
            + divSymbol
            + result.secondName
            + divSymbol
            + result.surname
            + divSymbol
            + result.group
            + divSymbol
            + QString::number(result.score)
            + divSymbol
            + QString::number(result.maxPosibleScore);

    for (int i = 0; i < result.answerInfo.count(); i++) {
        studentResult += divSymbol;
        studentResult += result.answerInfo.at(i).statement;
        studentResult += divSymbol;
        studentResult += result.answerInfo.at(i).chosenAnswer;
        studentResult += divSymbol;
        studentResult += QString::number(result.answerInfo.at(i).isCorrectAnswer);
        studentResult += divSymbol;
        studentResult += QString::number(result.answerInfo.at(i).assurance);
    }

    //non latin symbols have more size then latin,
    //so string length != real symbols array size
    QByteArray bytes = studentResult.toUtf8();
    //calculate msg sum
    int msgSize = headerMsgSize + bytes.length();

    //put data to bytearray
    QByteArray  arrBlock;
    arrBlock.fill(0, msgSize);
    arrBlock.insert(0, QString::number(msgSize));
    arrBlock.insert(headerMsgSize, studentResult);
    arrBlock.resize(msgSize);

    //send data to server
    qDebug() << m_pTcpSocket->write(arrBlock);
    m_pTcpSocket->waitForBytesWritten(3000);
}
示例#16
0
int main(int argc, char *argv[])
{
    if (argc <= 1)
        qFatal("Usage: %s FILES", argc ? argv[0] : "fixnonlatin1");
    for (int i = 1; i < argc; ++i) {

        QString fileName = QString::fromLocal8Bit(argv[i]);
        if (   fileName.endsWith(".gif")
            || fileName.endsWith(".jpg")
            || fileName.endsWith(".tif")
            || fileName.endsWith(".tiff")
            || fileName.endsWith(".png")
            || fileName.endsWith(".mng")
            || fileName.endsWith(".ico")
            || fileName.endsWith(".zip")
            || fileName.endsWith(".gz")
            || fileName.endsWith(".qpf")
            || fileName.endsWith(".ttf")
            || fileName.endsWith(".pfb")
            || fileName.endsWith(".exe")
            || fileName.endsWith(".nib")
            || fileName.endsWith(".o")
            )
            continue;

        QFile file(fileName);
        if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
            qFatal("Cannot open '%s': %s", argv[i], qPrintable(file.errorString()));

        QByteArray ba = file.readAll();
        bool mod = false;
        for (int j = 0; j < ba.count(); ++j) {
            uchar c = ba.at(j);
            if (c > 127) {
                ba[j] = '\\';
                ba.insert(j + 1, QByteArray::number(c, 8).rightJustified(3, '0', true));
                j += 3;
                mod = true;
            }
        }
        file.close();

        if (!mod)
            continue;

        qWarning("found non-latin1 characters in '%s'", argv[i]);
        if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
            qWarning("Cannot open '%s' for writing: %s", argv[i], qPrintable(file.errorString()));
            continue;
        }
        if (file.write(ba) < 0)
            qFatal("Error while writing into '%s': %s", argv[i], qPrintable(file.errorString()));
        file.close();
    }

    return 0;
}
示例#17
0
/*!
 * \param a Button pointer
 * \param ad Data
 *
 * Sets custom data for specified button.
 */
void IButtonBar::setActionData(QAction *a, action_data_t ad)
{
    char data[sizeof(action_data_t)];
    memcpy(data, (char*)&ad, sizeof(action_data_t));

    QByteArray ba;
    ba.insert(0, data, sizeof(action_data_t));

    a->setData(ba);
}
void TcpClient::sendFilesGettingRequest()
{
    QString cmd = cmdMsg;
    QByteArray bytes(cmd.toStdString().c_str());
    //calculate msg sum
    int msgSize = headerMsgSize + bytes.length();

    //put data to bytearray
    QByteArray  arrBlock;
    arrBlock.fill(0, msgSize);
    arrBlock.insert(0, QString::number(msgSize));
    arrBlock.insert(headerMsgSize, cmd);
    arrBlock.resize(msgSize);

    qDebug() << "client arr = " << arrBlock;
    //send data to server
    qDebug() << m_pTcpSocket->write(arrBlock);
    m_pTcpSocket->waitForBytesWritten(3000);
}
// convert binary MAC to hex string (human readable)
// e.g. 6-byte array -> 00:11:22:dd:ee:ff
QByteArray SettingDbus::macBin2Hex(const QByteArray &binMac)
{
    const int MAC_STR_LEN = 17;
    QByteArray ba = binMac;

    if (ba.isEmpty()) {
        return ba;
    }

    ba = ba.toHex().toUpper();
    ba.insert(2, ':');
    ba.insert(5, ':');
    ba.insert(8, ':');
    ba.insert(11, ':');
    ba.insert(14, ':');
    ba.resize(MAC_STR_LEN);

    return ba;
}
示例#20
0
void IsimControl::sendInstruction(quint8 length, quint8 instruction, float* params){
	QByteArray* instructionByteArray = new QByteArray();
	int instIndex = 0;
	/*Insert Start Index*/
	for (int i = 0; i < 3; i++){
		instructionByteArray->insert(instIndex++, 0x55);
	}
	/*Insert ID, Length, Instruction*/
	instructionByteArray->insert(instIndex++,(char)(this->id) );
	instructionByteArray->insert(instIndex++, length);
	instructionByteArray->insert(instIndex++, instruction);
	/*Insert Data*/
	for (int i = 0; i < length; i++)
	{
		bool isPostive;

		if (params[i] > 0){
			isPostive = true;
		}
		else{
			isPostive = false;
			params[i] = 0 - params[i];
		}


		qint16 param_H ;
		qint16 param_L ;
		
		param_H = (qint16)(((int)(params[i])) % 10000);
		param_L = (qint16)(((int)(params[i] * 10000.0)) % 10000);

		if (isPostive){
		}
		else{
			param_H = -(param_H);
			param_L = -(param_L);
		}

		instructionByteArray->insert(instIndex++, ((char*)&param_H) , 2);
		instIndex++;

		instructionByteArray->insert(instIndex++, ((char*)&param_L) , 2);
		instIndex++;
	}
	/*Insert CheckSum*/
	instructionByteArray->insert(instIndex++,0xFE);
	/*Send Data after checking port*/
	if (xbee->isOpen()){
		xbee->write(*instructionByteArray);
		xbee->waitForBytesWritten(-1);
	}
	else{

	}
	delete(instructionByteArray);
}
示例#21
0
void UmlOperation::setParams(const char * s)
{
    QByteArray d;
    int index;

    d = cppDecl();

    if (((index = d.indexOf("${(}")) != -1) &&
        (d.mid(index + 4, 4) == "${)}")) {
        d.insert(d.indexOf("${(}") + 4, s);
        set_CppDecl(d);
    }

    d = cppDef();

    if (((index = d.indexOf("${(}")) != -1) &&
        (d.mid(index + 4, 4) == "${)}")) {
        d.insert(d.indexOf("${(}") + 4, s);
        set_CppDef(d);
    }
}
/**
 * Method called by plugins to generate a signature string from a base string
 * @param aBaseString The base string
 * @return The md5 hash of the base string
 */
QString FlickrContactFetcherPlugin::generateSignature(const QString aBaseString)
	{
	qDebug()<<"Inside FlickrContactFetcherPlugin::generateSignature()";
	
	// Create md5 hash of the signature string
    QByteArray byteArray;
    byteArray.insert(0, aBaseString.toAscii());

    QByteArray md5Hash = QCryptographicHash::hash(byteArray,QCryptographicHash::Md5 ).toHex();
    QString returnString (md5Hash);
    qDebug()<<"generated signature = "<<QString(returnString);
    return returnString;
	}
示例#23
0
void WebSocketOutput::write(QByteArray &bytes)
{
    if (m_file) {
        if (m_firstWrite) {
            int pos = bytes.indexOf("\n");
            bytes.insert(pos+1, "X-OwNet-CachedOn: " + QDateTime::currentDateTimeUtc().toString(Qt::ISODate) + "\r\n");
            m_firstWrite = false;
        }
        m_file->write(bytes);
    }
    else if (m_socketHandler)
        m_socketHandler->write(bytes);
}
void TcpClient::sendDownLoadFileRequest(const QString &filename)
{
    qDebug() << "sendDownLoadFileRequest" << filename;
    if (!filename.isEmpty()) {
        //non latin symbols have more size then latin,
        //so string length != real symbols array size
        QByteArray bytes = filename.toUtf8();
        //calculate msg sum
        int msgSize = headerMsgSize + downloadMsg.length() + bytes.length();

        //put data to bytearray
        QByteArray  arrBlock;
        arrBlock.fill(0, msgSize);
        arrBlock.insert(0, QString::number(msgSize));
        arrBlock.insert(headerMsgSize, downloadMsg);
        arrBlock.insert(headerMsgSize + downloadMsg.length(), filename);
        arrBlock.resize(msgSize);

        //send data to server
        qDebug() << m_pTcpSocket->write(arrBlock);
        m_pTcpSocket->waitForBytesWritten(3000);
    }
}
示例#25
0
QString encodePassword(QString const &str)
{
	if (!str.isEmpty()) {
		char tmp[4];
		uint32_t t = QTime::currentTime().msecsSinceStartOfDay();
		tmp[0] = t >> 24;
		tmp[1] = t >> 16;
		tmp[2] = t >> 8;
		tmp[3] = t;
		QByteArray ba = str.toUtf8();
		ba.insert(0, tmp, 4);
		pseudo_crypto_encode(ba.data(), ba.size());
		ba = ba.toHex();
		return QString::fromUtf8(ba);
	}
示例#26
0
文件: capture.cpp 项目: AchillesL/ARM
//???
void Capture::readFrame()
{

    //frame = cvQueryFrame( capture );   //???
    // ?????QImage?QImage::Format_RGB888??ò???

    //img = QImage((const uchar*)frame->imageData,frame->width,frame->height,QImage::Format_RGB888);
    //ui->video_label->setPixmap(QPixmap::fromImage(img));  //video_label???

    //send_frame_flag?1?PC???
    if(1 == send_frame_flag)
    {
        QByteArray buf;
        QBuffer buffer(&buf);
        buffer.open(QIODevice::ReadWrite);
        this->image.save(&buffer, "JPG");

        qint64 res;
        ///111
        if(take_photo_flag)
            {
                buf.insert(0,'y');
                take_photo_flag=0;
            }
            else buf.insert(0,'n');
        ///111
        if((res = send_socket->writeDatagram(buf.data(),buf.size(),QHostAddress("10.13.23.89"),port)) != buf.length())
        {
            qDebug()<<"error";
            return;
        }
    }
    //videoWrite(frame);


}
示例#27
0
void UmlOperation::java(QHash<QByteArray, QByteArray*> & prop)
{
    QByteArray d = JavaSettings::operationDef();
    QByteArray * v;

    if ((v = prop.value("Java/Final")) != 0) {
        if (*v == "TRUE")
            set_isJavaFinal(TRUE);

        prop.remove("Java/Final");
    }

    if ((v = prop.value("Java/Synchronized")) != 0) {
        if (*v == "TRUE")
            set_isJavaSynchronized(TRUE);

        prop.remove("Java/Synchronized");
    }

    if ((v = prop.value("Java/Static")) != 0) {
        if (*v == "TRUE")
            set_isClassMember(TRUE);

        prop.remove("Java/Static");
    }

    if ((v = prop.value("Java/Abstract")) != 0) {
        if (*v == "TRUE")
            set_isAbstract(TRUE);

        prop.remove("Java/Abstract");
    }

    if ((v = prop.value("Java/Strictfp")) != 0) {
        if (*v == "TRUE") {
            int index = d.indexOf("${final}");

            if (index != -1)
                d.insert(index, "strictfp ");
        }

        prop.remove("Java/Strictfp");
    }

    set_JavaDef(d);
}
示例#28
0
void UmlClass::addContructor(bool expl)
{
    TRACE_FUNCTION;
    QLOG_INFO() << "1.1.1";
    UmlOperation * op = UmlOperation::create(this, name());
    QLOG_INFO() << "1.1.2";
    if (op == 0)
        UmlCom::trace("can't add contructor");
    else {
        QLOG_INFO() << "1.1.3";
        QByteArray s;
        int index;

        // remove the useless "${type} " mainly to remove the space

        s = op->cppDecl();
        QLOG_INFO() << s;
        QLOG_INFO() << "1.1.4";
        if (s.isEmpty())
            s = CppSettings::operationDecl();
        QLOG_INFO() << s;
        QLOG_INFO() << "1.1.5";
        if ((index = s.indexOf("${type} ")) != -1)
            s.remove(index, 8);
        QLOG_INFO() << s;
        QLOG_INFO() << "1.1.6";
        if (expl && ((index = s.indexOf("${name}")) != -1))
            s.insert(index, "explicit ");
        QLOG_INFO() << s;
        QLOG_INFO() << "1.1.7";
        op->set_CppDecl(s);
        QLOG_INFO() << s;
        QLOG_INFO() << "1.1.8";
        s = op->cppDef();
        QLOG_INFO() << s;
        QLOG_INFO() << "1.1.81";
        if (s.isEmpty())
            s = CppSettings::operationDef();
        QLOG_INFO() << "1.1.9";
        if ((index = s.indexOf("${type} ")) != -1)
            s.remove(index, 8);
        QLOG_INFO() << "1.1.10";
        op->set_CppDef(s);
    }
}
示例#29
0
QByteArray PublicKeyCrypto::boxAfterNM(const QByteArray &data, const QByteArray &nonce, const QByteArray &key)
{
    if(key.length() != boxBeforeNMBytes)
    {
        qDebug()<< "PublicKeyCrypto::boxAfterNM failed due to key length";
        return QByteArray();
    }
    if(nonce.length() != boxNonceBytes)
    {
        qDebug()<< "PublicKeyCrypto::boxAfterNM failed due to nonce length";
        return QByteArray();
    }

    QByteArray message ;//= data.leftJustified(boxZeroBytes);
    message.resize(boxZeroBytes);
    message.insert(boxZeroBytes, data);
    unsigned char * msg = toUnsignedChar(message.data());
    sodium_memzero(msg, boxZeroBytes);

    QByteArray cipher;
    size_t clen = message.length();
    cipher.resize(clen);
    if((size_t)cipher.length() != clen)
    {
        qDebug()<< "PublicKeyCrypto::boxAfterNM failed to resize ciphertext buffer";
        return QByteArray();
    }
    unsigned char *ctxt = toUnsignedChar(cipher.data());
    int result = crypto_box_afternm(
                ctxt,
                (const unsigned char *)msg, message.length(),
                toConstUnsignedChar(nonce.constData()),
                toConstUnsignedChar(key.constData()));

    if(result == TEARS_SODIUM_SUCCESS)
    {
        // Skip box zero bytes
        return cipher.mid(boxBoxZeroBytes);
    }
    else
    {
        qDebug()<<"PublicKeyCrypto::boxAfterNM call to crypto_box_afternm() failed";
        return QByteArray();
    }
}
示例#30
0
QByteArray PublicKeyCrypto::boxOpenAfterNM(const QByteArray &cipherData, const QByteArray &nonce, const QByteArray &key)
{
    if(key.length() != boxBeforeNMBytes)
    {
        qDebug()<< "PublicKeyCrypto::boxOpenAfterNM failed due to key length";
        return QByteArray();
    }
    if(nonce.length() != boxNonceBytes)
    {
        qDebug()<< "PublicKeyCrypto::boxOpenAfterNM failed due to nonce length";
        return QByteArray();
    }

    QByteArray ciphertext;
    ciphertext.resize(boxBoxZeroBytes);
    ciphertext.insert(boxBoxZeroBytes, cipherData);
    unsigned char * ctxt = toUnsignedChar(ciphertext.data());
    sodium_memzero(ctxt, boxBoxZeroBytes);

    QByteArray message;
    message.resize(ciphertext.length());
    if(message.length() != ciphertext.length())
    {
        qDebug()<< "PublicKeyCrypto::boxOpenAfterNM failed to allocate message buffer.";
        return QByteArray();
    }

    int result = crypto_box_open_afternm(
                toUnsignedChar(message.data()),
                ctxt, ciphertext.length(),
                toConstUnsignedChar(nonce.constData()),
                toConstUnsignedChar(key.constData())
                );
    if(result == TEARS_SODIUM_SUCCESS)
    {
        // Skip zero bytes
        return message.mid(boxZeroBytes);
    }
    else
    {
        qDebug()<< "PublicKeyCrypto::boxOpenAfterNM call to crypto_box_open_afternm() failed.";
        return QByteArray();
    }
}