bool QIODeviceProto::reset()
{
  QIODevice *item = qscriptvalue_cast<QIODevice*>(thisObject());
  if (item)
    return item->reset();
  return false;
}
Beispiel #2
0
void MemoryMap::diffWith(MemoryMap* other)
{
    _pmemDiff.clear();

    QIODevice* dev = _vmem->physMem();
    QIODevice* otherDev = other->vmem()->physMem();
    if (!otherDev || !dev)
        return;

    assert(dev != otherDev);

    // Open devices for reading, if required
    if (!dev->isReadable()) {
        if (dev->isOpen())
            dev->close();
        assert(dev->open(QIODevice::ReadOnly));
    }
    else
        assert(dev->reset());

    if (!otherDev->isReadable()) {
        if (otherDev->isOpen())
            otherDev->close();
        assert(otherDev->open(QIODevice::ReadOnly));
    }
    else
        assert(otherDev->reset());

    QTime timer;
    timer.start();
    bool wasEqual = true, equal = true;
    quint64 addr = 0, startAddr = 0, length = 0;
    const int bufsize = 1024;
    const int granularity = 16;
    char buf1[bufsize], buf2[bufsize];
    qint64 readSize1, readSize2;
    qint64 done, prevDone = -1;
    qint64 totalSize = qMin(dev->size(), otherDev->size());
    if (totalSize < 0)
        totalSize = qMax(dev->size(), otherDev->size());

    // Compare the complete physical address space
    while (!Console::interrupted() && !dev->atEnd() && !otherDev->atEnd()) {
        readSize1 = dev->read(buf1, bufsize);
        readSize2 = otherDev->read(buf2, bufsize);

        if (readSize1 <= 0 || readSize2 <= 0)
            break;

        qint64 size = qMin(readSize1, readSize2);
        for (int i = 0; i < size; ++i) {
            if (buf1[i] != buf2[i])
                equal = false;
            // We only consider memory chunks of size "granularity"
            if (addr % granularity == granularity - 1) {
                // Memory is equal
                if (equal) {
                    // Add difference to tree
                    if (!wasEqual)
                        _pmemDiff.insert(Difference(startAddr, length));
                }
                // Memory differs
                else {
                    // Start new difference
                    if (wasEqual) {
                        startAddr = addr - (addr % granularity);
                        length = granularity;
                    }
                    // Enlarge difference
                    else
                        length += granularity;
                }
                wasEqual = equal;
            }
            ++addr;
            equal = true;
        }

        done = (int) (addr / (float) totalSize * 100);
        if (prevDone < 0 || (done != prevDone && timer.elapsed() > 500)) {
            Console::out() << "\rComparing memory dumps: " << done << "%" << flush;
            prevDone = done;
            timer.restart();
        }
    }

    // Add last difference, if any
    if (!wasEqual)
        _pmemDiff.insert(Difference(startAddr, length));

    Console::out() << "\rComparing memory dumps finished." << endl;

//    debugmsg("No. of differences: " << _pmemDiff.objectCount());
}
Beispiel #3
0
bool EPSHandler::read(QImage *image)
{
    kDebug(399) << "kimgio EPS: starting...";

    FILE * ghostfd;
    int x1, y1, x2, y2;
    //QTime dt;
    //dt.start();

    QString cmdBuf;
    QString tmp;

    QIODevice* io = device();
    quint32 ps_offset, ps_size;

    // find start of PostScript code
    if ( !seekToCodeStart(io, ps_offset, ps_size) )
        return false;

    // find bounding box
    if ( !bbox (io, &x1, &y1, &x2, &y2)) {
        kError(399) << "kimgio EPS: no bounding box found!" << endl;
        return false;
    }

    QTemporaryFile tmpFile;
    if( !tmpFile.open() ) {
        kError(399) << "kimgio EPS: no temp file!" << endl;
        return false;
    }

    // x1, y1 -> translation
    // x2, y2 -> new size

    x2 -= x1;
    y2 -= y1;
    //kDebug(399) << "origin point: " << x1 << "," << y1 << "  size:" << x2 << "," << y2;
    double xScale = 1.0;
    double yScale = 1.0;
    int wantedWidth = x2;
    int wantedHeight = y2;

    // create GS command line

    cmdBuf = "gs -sOutputFile=";
    cmdBuf += tmpFile.fileName();
    cmdBuf += " -q -g";
    tmp.setNum( wantedWidth );
    cmdBuf += tmp;
    tmp.setNum( wantedHeight );
    cmdBuf += 'x';
    cmdBuf += tmp;
    cmdBuf += " -dSAFER -dPARANOIDSAFER -dNOPAUSE -sDEVICE=ppm -c "
              "0 0 moveto "
              "1000 0 lineto "
              "1000 1000 lineto "
              "0 1000 lineto "
              "1 1 254 255 div setrgbcolor fill "
              "0 0 0 setrgbcolor - -c showpage quit";

    // run ghostview

    ghostfd = popen (QFile::encodeName(cmdBuf), "w");

    if ( ghostfd == 0 ) {
        kError(399) << "kimgio EPS: no GhostScript?" << endl;
        return false;
    }

    fprintf (ghostfd, "\n%d %d translate\n", -qRound(x1*xScale), -qRound(y1*yScale));

    // write image to gs

    io->reset(); // Go back to start of file to give all the file to GhostScript
    if (ps_offset>0L) // We have an offset
        io->seek(ps_offset);
    QByteArray buffer ( io->readAll() );

    // If we have no MS-DOS EPS file or if the size seems wrong, then choose the buffer size
    if (ps_size<=0 || ps_size>(unsigned int)buffer.size())
        ps_size=buffer.size();

    fwrite(buffer.data(), sizeof(char), ps_size, ghostfd);
    buffer.resize(0);

    pclose ( ghostfd );

    // load image
    if( image->load (tmpFile.fileName()) ) {
        kDebug(399) << "kimgio EPS: success!";
        //kDebug(399) << "Loading EPS took " << (float)(dt.elapsed()) / 1000 << " seconds";
        return true;
    }

    kError(399) << "kimgio EPS: no image!" << endl;
    return false;
}
Beispiel #4
0
KDE_EXPORT void kimgio_eps_read(QImageIO *image)
{
    kdDebug(399) << "kimgio EPS: starting..." << endl;

    FILE *ghostfd;
    int x1, y1, x2, y2;
    // QTime dt;
    // dt.start();

    QString cmdBuf;
    QString tmp;

    QIODevice *io = image->ioDevice();
    Q_UINT32 ps_offset, ps_size;

    // find start of PostScript code
    if(!seekToCodeStart(io, ps_offset, ps_size))
        return;

    // find bounding box
    if(!bbox(io, &x1, &y1, &x2, &y2))
    {
        kdError(399) << "kimgio EPS: no bounding box found!" << endl;
        return;
    }

    KTempFile tmpFile;
    tmpFile.setAutoDelete(true);

    if(tmpFile.status() != 0)
    {
        kdError(399) << "kimgio EPS: no temp file!" << endl;
        return;
    }
    tmpFile.close(); // Close the file, we just want the filename

    // x1, y1 -> translation
    // x2, y2 -> new size

    x2 -= x1;
    y2 -= y1;
    // kdDebug(399) << "origin point: " << x1 << "," << y1 << "  size:" << x2 << "," << y2 << endl;
    double xScale = 1.0;
    double yScale = 1.0;
    bool needsScaling = false;
    int wantedWidth = x2;
    int wantedHeight = y2;

    if(image->parameters())
    {
        // Size forced by the caller
        QStringList params = QStringList::split(':', image->parameters());
        if(params.count() >= 2 && x2 != 0.0 && y2 != 0.0)
        {
            wantedWidth = params[0].toInt();
            xScale = (double)wantedWidth / (double)x2;
            wantedHeight = params[1].toInt();
            yScale = (double)wantedHeight / (double)y2;
            // kdDebug(399) << "wanted size:" << wantedWidth << "x" << wantedHeight << endl;
            // kdDebug(399) << "scaling:" << xScale << "," << yScale << endl;
            needsScaling = true;
        }
    }

    // create GS command line

    cmdBuf = "gs -sOutputFile=";
    cmdBuf += tmpFile.name();
    cmdBuf += " -q -g";
    tmp.setNum(wantedWidth);
    cmdBuf += tmp;
    tmp.setNum(wantedHeight);
    cmdBuf += "x";
    cmdBuf += tmp;
    cmdBuf +=
        " -dSAFER -dPARANOIDSAFER -dNOPAUSE -sDEVICE=ppm -c "
        "0 0 moveto "
        "1000 0 lineto "
        "1000 1000 lineto "
        "0 1000 lineto "
        "1 1 254 255 div setrgbcolor fill "
        "0 0 0 setrgbcolor - -c showpage quit";

    // run ghostview

    ghostfd = popen(QFile::encodeName(cmdBuf), "w");

    if(ghostfd == 0)
    {
        kdError(399) << "kimgio EPS: no GhostScript?" << endl;
        return;
    }

    fprintf(ghostfd, "\n%d %d translate\n", -qRound(x1 * xScale), -qRound(y1 * yScale));
    if(needsScaling)
        fprintf(ghostfd, "%g %g scale\n", xScale, yScale);

    // write image to gs

    io->reset();       // Go back to start of file to give all the file to GhostScript
    if(ps_offset > 0L) // We have an offset
        io->at(ps_offset);
    QByteArray buffer(io->readAll());

    // If we have no MS-DOS EPS file or if the size seems wrong, then choose the buffer size
    if(ps_size <= 0L || ps_size > buffer.size())
        ps_size = buffer.size();

    fwrite(buffer.data(), sizeof(char), ps_size, ghostfd);
    buffer.resize(0);

    pclose(ghostfd);

    // load image
    QImage myimage;
    if(myimage.load(tmpFile.name()))
    {
        image->setImage(myimage);
        image->setStatus(0);
        kdDebug(399) << "kimgio EPS: success!" << endl;
    }
    else
        kdError(399) << "kimgio EPS: no image!" << endl;

    // kdDebug(399) << "Loading EPS took " << (float)(dt.elapsed()) / 1000 << " seconds" << endl;
    return;
}
Beispiel #5
0
void uWSGI::processRequest(wsgi_request *req)
{
    CachedRequest *cache = static_cast<CachedRequest *>(req->async_environ);

    // wsgi_req->uri containg the whole URI it /foo/bar?query=null
    // so we use path_info, maybe it would be better to just build our
    // Request->uri() from it, but we need to run a performance test
    uint16_t pos = notSlash(req->path_info, req->path_info_len);
    const QString path = QString::fromLatin1(req->path_info + pos, req->path_info_len - pos);

    const QString serverAddress = QString::fromLatin1(req->host, req->host_len);
    const QByteArray query = QByteArray::fromRawData(req->query_string, req->query_string_len);

    const QString method = QString::fromLatin1(req->method, req->method_len);
    const QString protocol = QString::fromLatin1(req->protocol, req->protocol_len);
    const QString remoteAddress = QString::fromLatin1(req->remote_addr, req->remote_addr_len);
    const QString remoteUser = QString::fromLatin1(req->remote_user, req->remote_user_len);

    quint16 remotePort = 0;
    Headers headers;
    // we scan the table in reverse, as updated values are at the end
    for (int i = req->var_cnt - 1; i > 0; i -= 2) {
        struct iovec &name = req->hvec[i - 1];
        struct iovec &value = req->hvec[i];
        if (!uwsgi_startswith(static_cast<char *>(name.iov_base),
                              const_cast<char *>("HTTP_"), 5)) {
            headers.setHeader(QString::fromLatin1(static_cast<char *>(name.iov_base) + 5, name.iov_len - 5),
                              QString::fromLatin1(static_cast<char *>(value.iov_base), value.iov_len));
        } else if (!remotePort &&
                   !uwsgi_strncmp(const_cast<char *>("REMOTE_PORT"), 11,
                                  static_cast<char *>(name.iov_base), name.iov_len)) {
            remotePort = QByteArray::fromRawData(static_cast<char *>(value.iov_base), value.iov_len).toUInt();
        }
    }

    if (req->content_type_len > 0) {
        headers.setContentType(QString::fromLatin1(req->content_type, req->content_type_len));
    }

    if (req->encoding_len > 0) {
        headers.setContentEncoding(QString::fromLatin1(req->encoding, req->encoding_len));
    }

    QIODevice *body;
    if (req->post_file) {
//        qCDebug(CUTELYST_UWSGI) << "Post file available:" << req->post_file;
        QFile *upload = cache->bodyFile;
        if (upload->open(req->post_file, QIODevice::ReadOnly)) {
            body = upload;
        } else {
//            qCDebug(CUTELYST_UWSGI) << "Could not open post file:" << upload->errorString();
            body = cache->bodyBufferedUWSGI;
            body->open(QIODevice::ReadOnly | QIODevice::Unbuffered);
        }
    } else if (uwsgi.post_buffering) {
//        qCDebug(CUTELYST_UWSGI) << "Post buffering size:" << uwsgi.post_buffering;
        body = cache->bodyUWSGI;
        body->reset();
    } else {
        // BodyBufferedUWSGI is an IO device which will
        // only consume the body when some of it's functions
        // is called, this is because here we can't seek
        // the body.
        body = cache->bodyBufferedUWSGI;
        body->open(QIODevice::ReadOnly | QIODevice::Unbuffered);
    }

    Engine::processRequest(method,
                           path,
                           query,
                           protocol,
                           req->https_len,
                           serverAddress,
                           remoteAddress,
                           remotePort,
                           remoteUser,
                           headers,
                           req->start_of_request,
                           body,
                           req);

    body->close();
}