Beispiel #1
0
TEST(SystematicObjects, ResolutionScaleSystematicConstructor) {
  pdfz::ResolutionScaleSystematic syst(0, 2, 1);
  EXPECT_EQ(pdfz::Systematic::RESOLUTION_SCALE, syst.type);
  EXPECT_EQ(0, syst.obs);
  EXPECT_EQ(2, syst.true_obs);
  EXPECT_EQ(1, syst.par);
}
Beispiel #2
0
void ClientThread::analizeCommand(QByteArray &bytearray){
    QString userName;
    if (bytearray.contains("USER")) {
        QRegExp rx("^USER\\s(.*)");
        rx.indexIn(bytearray);
        userName = rx.cap(1);
        mUser = User::getUser(userName);
        sendString(FTPProtocol::getInstance()->getResponse(331));
        return;
    }

    if (bytearray.contains("PASS")) {
        QRegExp rx("^PASS\\s(.*)");
        rx.indexIn(bytearray);
        QString pass = rx.cap(1);
        if (mUser.isNull())
        {
            sendString(FTPProtocol::getInstance()->getResponse(503,"PASS send before USER"));
        }
        else
        {
            if (mUser.auth(pass))
            {
                // logged in
                 sendString(FTPProtocol::getInstance()->getResponse(230));
                 setAuthenticated(true);
                 if (ftpFileSystem != NULL)
                    delete ftpFileSystem;
                 ftpFileSystem = new FtpFileSystem(mUser.getFolder(), mUser.getFileAccess());
            }
            else
            {
                // incorrect
                 sendString(FTPProtocol::getInstance()->getResponse(530));
            }
        }
        return;
    }
    if (isAuthenticated())
    {
        // RNFR -> RNTO sequence
        if (mRenameBeginned){
            if (bytearray.contains("RNTO")){
                QRegExp rx("^RNTO\\s(.*)");
                rx.indexIn(fromEncoding(bytearray));
                QString newName = rx.cap(1);
                mRenameBeginned = false;
                if (ftpFileSystem->rename(mRenameOldName, newName))
                    sendString(FTPProtocol::getInstance()->getResponse(250));
                else
                    sendString(FTPProtocol::getInstance()->getResponse(550));
                return;
            }
            sendString(FTPProtocol::getInstance()->getResponse(503));
            return;
        }
        if (bytearray.contains("SYST")){
            QString syst("Windows Type : L8");
            sendString(FTPProtocol::getInstance()->getResponse(215, syst));
            return;
        }
        if (bytearray.contains("FEAT")){
            QString syst("211-Features:\n\rMDTM\n\rREST STREAM\n\rSIZE\n\rMLST type*;size*;modify*;\n\rMLSD\n\rUTF8\n\rCLNT\n\rMFMT\n\r211 End");
            sendString(syst);
            return;
        }
        if (bytearray.contains("HELP")){
            QString syst("HELP OK");
            sendString(FTPProtocol::getInstance()->getResponse(214, syst));
            return;
        }
        if (bytearray.contains("PWD")){
            sendString(FTPProtocol::getInstance()->getResponse(257, toEncoding("\""+ftpFileSystem->getWorkingDirectory()+"\"")));
            return;
        }
        if (bytearray.contains("OPTS")){
            QRegExp rx("^OPTS ([\\w\\s]+)");
            rx.indexIn(bytearray);
            QRegExp rx2("^UTF8 (\\w+)");
            rx2.indexIn(rx.cap(1));
            if (rx2.cap(1) == "ON")
            {
                mIsUTF8 = true;
            }
            if (rx2.cap(1) == "OFF")
            {
                mIsUTF8 = false;
            }
            sendString(FTPProtocol::getInstance()->getResponse(200));
            return;
        }
        if (bytearray.contains("TYPE")){
            // set transfer type
            QRegExp rx("^TYPE (\\w)( (\\w))?");
            rx.indexIn(bytearray);
            qDebug() << "type" << rx.cap(1) << rx.cap(3);
            mType = rx.cap(1);
            sendString(FTPProtocol::getInstance()->getResponse(200));
            return;
            if (mType == "I")
            {
                sendString(FTPProtocol::getInstance()->getResponse(200));
            }
            else
            {
                sendString(FTPProtocol::getInstance()->getResponse(550));
            }
            return;
        }
        if (bytearray.contains("PORT")){
            mIsActiveMode = true;
            QRegExp rx("^PORT (\\d+),(\\d+),(\\d+),(\\d+),(\\d+),(\\d+)");
            rx.indexIn(bytearray);
            int p1,p2;
            QString buf(rx.cap(5));
            bool flag;
            p1 = rx.cap(5).toInt(&flag);
            p2 = rx.cap(6).toInt(&flag);
            QString addr = rx.cap(1)+"."+rx.cap(2)+"."+rx.cap(3)+"."+rx.cap(4);
            active_addr = addr;
            active_port = p1*256+p2;
            sendString(FTPProtocol::getInstance()->getResponse(200, "Port ok"));
            return;
        }

        if (bytearray.contains("LIST")){
            sendString(FTPProtocol::getInstance()->getResponse(150));
            sendList();
            sendString(FTPProtocol::getInstance()->getResponse(226));
            return;
        }
        if (bytearray.contains("QUIT")){
            sendString(FTPProtocol::getInstance()->getResponse(221));
            closeconnection();
            return;
        }
        if (bytearray.contains("CDUP")){
            if (ftpFileSystem->cdUp())
                sendString(FTPProtocol::getInstance()->getResponse(250));
            else
                sendString(FTPProtocol::getInstance()->getResponse(550));
            return;
        }
        if (bytearray.contains("CWD")){
            QRegExp rx("^CWD\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            QString subFolder = rx.cap(1);
            if (ftpFileSystem->changeDir(subFolder))
                sendString(FTPProtocol::getInstance()->getResponse(250));
            else
                sendString(FTPProtocol::getInstance()->getResponse(550));
            return;
        }
        if (bytearray.contains("RETR")){
            QRegExp rx("^RETR\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            QString filename = rx.cap(1);
            QString fullFileName = ftpFileSystem->getFileRead(filename);
            if (fullFileName != NULL)
            {
                sendString(FTPProtocol::getInstance()->getResponse(150));
                sendFile(fullFileName);
            }
            else
            {
                sendString(FTPProtocol::getInstance()->getResponse(550,"Permission denied"));
            }
            return;
        }
        if (bytearray.contains("STOR")){
            QRegExp rx("^STOR\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            QString filename = rx.cap(1);
            QString fullFileName = ftpFileSystem->getFileWrite(filename);
            if (fullFileName != NULL)
            {
                sendString(FTPProtocol::getInstance()->getResponse(150));
                recvFile(fullFileName);
            }
            else
            {
                sendString(FTPProtocol::getInstance()->getResponse(550,"Permission denied"));
            }
            return;
        }
        if (bytearray.contains("RMD")){
            QRegExp rx("^RMD\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            QString filename = rx.cap(1);
            if (ftpFileSystem->removeDir(filename))
                sendString(FTPProtocol::getInstance()->getResponse(250));
            else
                sendString(FTPProtocol::getInstance()->getResponse(550));
            return;
        }
        if (bytearray.contains("DELE")){
            QRegExp rx("^DELE\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            QString filename = rx.cap(1);
            if (ftpFileSystem->deleteFile(filename))
                sendString(FTPProtocol::getInstance()->getResponse(250));
            else
                sendString(FTPProtocol::getInstance()->getResponse(550));
            return;
        }
        if (bytearray.contains("MKD")){
            QRegExp rx("^MKD\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            QString dirName = rx.cap(1);
            if (ftpFileSystem->mkDir(dirName))
                sendString(FTPProtocol::getInstance()->getResponse(250));
            else
                sendString(FTPProtocol::getInstance()->getResponse(550));
            return;
        }
        if (bytearray.contains("PASV")){
            mIsActiveMode = false;
            selectPassivePort();
            return;
        }
        if (bytearray.contains("SIZE")){
            QRegExp rx("^SIZE\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            QString fileName = rx.cap(1);
            qint64 size;
            if (ftpFileSystem->getSize(fileName, &size))
            {
                sendString(FTPProtocol::getInstance()->getResponse(250, QString::number(size)));
            }
            else
            {
               sendString(FTPProtocol::getInstance()->getResponse(550));
            }
            return;
        }
        if (bytearray.contains("MDTM")){
            QRegExp rx("^MDTM\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            QString fileName = rx.cap(1);
            QString sdate = ftpFileSystem->getLastModified(fileName);
            if (sdate != NULL)
            {
                sendString(FTPProtocol::getInstance()->getResponse(250, sdate));
            }
            else
            {
               sendString(FTPProtocol::getInstance()->getResponse(550));
            }
            return;
        }
        if (bytearray.contains("RNFR")){
            QRegExp rx("^RNFR\\s(.*)");
            rx.indexIn(fromEncoding(bytearray));
            mRenameOldName = rx.cap(1);

            if (ftpFileSystem->exist(mRenameOldName) && ftpFileSystem->isWritable(mRenameOldName))
            {
                sendString(FTPProtocol::getInstance()->getResponse(350));
                mRenameBeginned = true;
            }
            else
                sendString(FTPProtocol::getInstance()->getResponse(550, "Permission denied"));
            return;
        }
    sendString(FTPProtocol::getInstance()->getResponse(500));
    }
    else
        sendString(FTPProtocol::getInstance()->getResponse(530));
}
Beispiel #3
0
TEST(SystematicObjects, ScaleSystematicConstructor) {
  pdfz::ScaleSystematic syst(0, 3);
  EXPECT_EQ(pdfz::Systematic::SCALE, syst.type);
  EXPECT_EQ(0, syst.obs);
  EXPECT_EQ(3, syst.par);
}
Beispiel #4
0
TEST(SystematicObjects, ShiftSystematicConstructor) {
  pdfz::ShiftSystematic syst(1, 0);
  EXPECT_EQ(pdfz::Systematic::SHIFT, syst.type);
  EXPECT_EQ(1, syst.obs);
  EXPECT_EQ(0, syst.par);
}