コード例 #1
0
bool QIODeviceProto::getChar(char *c)
{
  QIODevice *item = qscriptvalue_cast<QIODevice*>(thisObject());
  if (item)
    return item->getChar(c);
  return false;
}
コード例 #2
0
ファイル: nicookie.cpp プロジェクト: diginatu/nicookie
bool Nicookie::checkSameStr(QIODevice &device, const QString &str)
{
    char input_c;
    for (auto &c: str) {
        if (!device.getChar(&input_c)) {
            setError(Nicookie::FailedReadDataError);
            return false;
        }
        if (c != input_c) return false;
    }
    if (!device.getChar(&input_c)) {
        setError(Nicookie::FailedReadDataError);
        return false;
    }
    if (input_c != '\0') return false;
    return true;
}
コード例 #3
0
ファイル: qiodeviceproto.cpp プロジェクト: xtuple/qt-client
// Javascript does not support pass by reference String parameters. Return char instead.
//bool QIODeviceProto::getChar(char *c)
char QIODeviceProto::getChar()
{
  char c;
  QIODevice *item = qscriptvalue_cast<QIODevice*>(thisObject());
  if (item) {
    if (item->getChar(&c)) {
      return c;
    } else {
      return false;
    }
  }
  return false;
}
コード例 #4
0
ファイル: nicookie.cpp プロジェクト: diginatu/nicookie
QString Nicookie::readStr(QIODevice &device)
{
    QString str;
    while (true) {
        char input_c;
        if (!device.getChar(&input_c)) {
            setError(Nicookie::FailedReadDataError);
            return QString();
        }
        if (input_c == '\0') {
            break;
        } else {
            str.append(input_c);
        }
    }
    return str;
}
コード例 #5
0
ファイル: qmqtt_ssl_network.cpp プロジェクト: ve7mjc/qmqtt
int QMQTT::SslNetwork::readRemainingLength()
{
     quint8 byte = 0;
     int length = 0;
     int multiplier = 1;
     QIODevice *ioDevice = _socket->ioDevice();
     do {
         if (!ioDevice->getChar(reinterpret_cast<char *>(&byte)))
             return -1;
         length += (byte & 127) * multiplier;
         multiplier *= 128;
         if (multiplier > 128*128*128)
             return -1;
     } while ((byte & 128) != 0);

     return length;
}
コード例 #6
0
ファイル: qmqtt_ssl_network.cpp プロジェクト: ve7mjc/qmqtt
void QMQTT::SslNetwork::onSocketReadReady()
{
    QIODevice *ioDevice = _socket->ioDevice();
    while(!ioDevice->atEnd())
    {
        if(_bytesRemaining == 0)
        {
            if (!ioDevice->getChar(reinterpret_cast<char *>(&_header)))
            {
                // malformed packet
                emit error(QAbstractSocket::OperationError);
                ioDevice->close();
                return;
            }

            _bytesRemaining = readRemainingLength();
            if (_bytesRemaining < 0)
            {
                // malformed remaining length
                emit error(QAbstractSocket::OperationError);
                ioDevice->close();
                return;
            }
        }

        QByteArray data = ioDevice->read(_bytesRemaining);
        _buffer.append(data);
        _bytesRemaining -= data.size();

        if(_bytesRemaining == 0)
        {
            Frame frame(_header, _buffer);
            _buffer.clear();
            emit received(frame);
        }
    }
}
コード例 #7
0
ファイル: record.cpp プロジェクト: Holdlen2DH/QSanguosha
bool Record::open()
{
    QIODevice *device = new QFile(m_fileName);
    if (!device->open(QFile::ReadOnly))
        return false;

    char header;
    device->getChar(&header);
    if (header == '\0') {
        m_format = CompressedText;
        QByteArray content = device->readAll();
        delete device;

        QByteArray *data = new QByteArray(qUncompress(content));
        device = new QBuffer(data);
        device->open(QFile::ReadOnly);
    } else {
        m_format = PlainText;
        device->ungetChar(header);
        device->seek(0);
    }

    m_commands.clear();
    while (!device->atEnd()) {
        QByteArray line = device->readLine();
        int split = line.indexOf(' ');

        Command command;
        command.elapsed = line.left(split).toInt();
        command.data = line.mid(split + 1);

        m_commands << command;
    }

    return true;
}
コード例 #8
0
ファイル: tst_qiodevice.cpp プロジェクト: KDE/android-qt
//--------------------------------------------------------------------
void tst_QIODevice::unget()
{
#if defined(Q_OS_WINCE) && defined(WINCE_EMULATOR_TEST)
    QSKIP("Networking tests in a WinCE emulator are unstable", SkipAll);
#endif
    QBuffer buffer;
    buffer.open(QBuffer::ReadWrite);
    buffer.write("ZXCV");
    buffer.seek(0);
    QCOMPARE(buffer.read(4), QByteArray("ZXCV"));
    QCOMPARE(buffer.pos(), qint64(4));

    buffer.ungetChar('a');
    buffer.ungetChar('b');
    buffer.ungetChar('c');
    buffer.ungetChar('d');

    QCOMPARE(buffer.pos(), qint64(0));

    char buf[6];
    QCOMPARE(buffer.readLine(buf, 5), qint64(4));
    QCOMPARE(buffer.pos(), qint64(4));
    QCOMPARE(static_cast<const char*>(buf), "dcba");

    buffer.ungetChar('a');
    buffer.ungetChar('b');
    buffer.ungetChar('c');
    buffer.ungetChar('d');

    QCOMPARE(buffer.pos(), qint64(0));

    for (int i = 0; i < 5; ++i) {
        buf[0] = '@';
        buf[1] = '@';
        QTest::ignoreMessage(QtWarningMsg,
                             "QIODevice::readLine: Called with maxSize < 2");
        QCOMPARE(buffer.readLine(buf, 1), qint64(-1));
        QCOMPARE(buffer.readLine(buf, 2), qint64(i < 4 ? 1 : -1));
        switch (i) {
        case 0:
            QCOMPARE(buf[0], 'd');
            break;
        case 1:
            QCOMPARE(buf[0], 'c');
            break;
        case 2:
            QCOMPARE(buf[0], 'b');
            break;
        case 3:
            QCOMPARE(buf[0], 'a');
            break;
        case 4:
            QCOMPARE(buf[0], '\0');
            break;
        }
        QCOMPARE(buf[1], i < 4 ? '\0' : '@');
    }

    buffer.ungetChar('\n');
    QCOMPARE(buffer.readLine(), QByteArray("\n"));

    buffer.seek(1);
    buffer.readLine(buf, 3);
    QCOMPARE(static_cast<const char*>(buf), "XC");

    buffer.seek(4);
    buffer.ungetChar('Q');
    QCOMPARE(buffer.readLine(buf, 3), qint64(1));

    for (int i = 0; i < 2; ++i) {
        QTcpSocket socket;
        QIODevice *dev;
        QByteArray result;
        const char *lineResult;
        if (i == 0) {
            dev = &buffer;
            result = QByteArray("ZXCV");
            lineResult = "ZXCV";
        } else {
            socket.connectToHost(QtNetworkSettings::serverName(), 80);
            socket.write("GET / HTTP/1.0\r\n\r\n");
            QVERIFY(socket.waitForReadyRead());
            dev = &socket;
            result = QByteArray("HTTP");
            lineResult = "Date";
        }
        char ch, ch2;
        dev->seek(0);
        dev->getChar(&ch);
        dev->ungetChar(ch);
        QCOMPARE(dev->peek(4), result);
        dev->getChar(&ch);
        dev->getChar(&ch2);
        dev->ungetChar(ch2);
        dev->ungetChar(ch);
        QCOMPARE(dev->read(1), result.left(1));
        QCOMPARE(dev->read(3), result.right(3));

        if (i == 0)
            dev->seek(0);
        else
            dev->readLine();
        dev->getChar(&ch);
        dev->ungetChar(ch);
        dev->readLine(buf, 5);
        QCOMPARE(static_cast<const char*>(buf), lineResult);

        if (i == 1)
            socket.close();
    }
}
コード例 #9
0
bool PSCommentLexer::parse(QIODevice& fin)
{
    char c;

    m_buffer.clear();
    m_curState = State_Start;

    parsingStarted();

    while (!fin.atEnd()) {
        fin.getChar(&c);

//    qDebug ("got %c", c);

        State newState;
        Action action;

        nextStep(c, &newState, &action);

        switch (action) {
        case Action_Copy :
            m_buffer.append(c);
            break;
        case Action_CopyOutput :
            m_buffer.append(c);
            doOutput();
            break;
        case Action_Output :
            doOutput();
            break;
        case Action_OutputUnget :
            doOutput();
            fin.ungetChar(c);
            break;
        case Action_Ignore :
            /* ignore */
            break;
        case Action_Abort :
            qWarning("state %s / %s char %c (%d)" , statetoa(m_curState), statetoa(newState), c, c);
            parsingAborted();
            return false;
            break;
        case Action_InitTemp :
            m_temp.clear();
            break;
        case Action_CopyTemp :
            m_temp.append(c);
            break;
        case Action_DecodeUnget :
            m_buffer.append(decode());
            fin.ungetChar(c);
            break;
        default :
            qWarning("unknown action: %d ", action);
        }

        m_curState = newState;
    }

    parsingFinished();
    return true;
}