Exemplo n.º 1
0
QString Api::getDefaultPatcherSecret(CancellationToken cancellationToken) const
{
    qInfo() << "Getting the default patcher secret";
    QString path = "1/system/patchers";

    QJsonDocument document = get(path, cancellationToken);

    if (!document.isArray())
    {
        throw InvalidFormatException("Expected document root to be array");
    }

    QJsonArray array = document.array();

    QString platformString = Globals::currentPlatformString();

    for (QJsonValueRef item : array)
    {
        if (item.isObject())
        {
            QJsonObject object = item.toObject();

            if (object.contains(platformString))
            {
                return object[platformString].toString();
            }
        }
    }

    throw InvalidFormatException("Failed to resolve patcher for platform " + platformString);
}
Exemplo n.º 2
0
void BgzfReader::seek(VirtualOffset offset) {
    if((offset.getCoffset() == headerOffset) && (offset.getUoffset() >= (int)stream.total_out)) {
        qint64 toSkip = offset.getUoffset() - stream.total_out;
        if(skip(toSkip) < toSkip) {
            coreLog.error(QString("in BgzfReader::seek, cannot seek to offset {coffset=%1,uoffset=%2}, failed to skip %3")
                          .arg(offset.getCoffset())
                          .arg(offset.getUoffset())
                          .arg(toSkip));
            throw InvalidFormatException(BAMDbiPlugin::tr("Unexpected end of file"));
        }
    } else {
        qint64 toSkipIo = offset.getCoffset() - ioAdapter.bytesRead();
        if(!ioAdapter.skip(toSkipIo)) {
            coreLog.error(QString("in BgzfReader::seek, cannot seek to offset {coffset=%1,uoffset=%2}, ioAdapter failed to skip %3")
                          .arg(offset.getCoffset())
                          .arg(offset.getUoffset())
                          .arg(toSkipIo));
            throw IOException(BAMDbiPlugin::tr("Can't read input"));
        }
        stream.next_in = Z_NULL;
        stream.avail_in = 0;
        headerOffset = ioAdapter.bytesRead();
        inflateReset(&stream);
        qint64 toSkip = offset.getUoffset();
        if(skip(toSkip) < toSkip) {
            coreLog.error(QString("in BgzfReader::seek, cannot seek to offset {coffset=%1,uoffset=%2}, failed to skip %3 after ioAdapter skipped %4")
                          .arg(offset.getCoffset())
                          .arg(offset.getUoffset())
                          .arg(toSkip)
                          .arg(toSkipIo));
            throw InvalidFormatException(BAMDbiPlugin::tr("Unexpected end of file"));
        }
    }
    endOfFile = false;
}
Exemplo n.º 3
0
QString Api::getPatcherSecret(const QString &appSecret, CancellationToken cancellationToken) const
{
    qInfo() << "Getting the patcher secret for app " << appSecret;
    auto path = QString("1/apps/%1")
            .arg(appSecret);

    QJsonDocument document = get(path, cancellationToken);

    if (!document.isObject())
    {
        throw InvalidFormatException("Expected document root to be object");
    }

    if (!document.object().contains("patcher_secret"))
    {
        throw InvalidFormatException("Document did not contain the 'patcher_secret' field");
    }

    if (!document.object()["patcher_secret"].isString())
    {
        throw InvalidFormatException("patcher_secret was not a string");
    }

    return document.object()["patcher_secret"].toString();
}
Exemplo n.º 4
0
int Api::getLatestAppVersion(const QString &appSecret, CancellationToken cancellationToken) const
{
    qInfo() << "Getting the latest app version for app " << appSecret;
    auto path = QString("1/apps/%1/versions/latest/id")
            .arg(appSecret);

    QJsonDocument document = get(path, cancellationToken);

    if (!document.isObject())
    {
        throw InvalidFormatException("Expected document root to be object");
    }

    if (!document.object().contains("id"))
    {
        throw InvalidFormatException("Document did not contain the 'id' field");
    }

    if (!document.object()["id"].isDouble())
    {

    }

    int id = document.object()["id"].toInt(-1);

    if (id == -1)
    {
        throw InvalidFormatException("Value of 'id' field was not an integer");
    }

    return id;
}
Exemplo n.º 5
0
            void ParserModel::validateArtifactMap() throw(InvalidFormatException)
            {
              BaseModel::validateArtifactMap();

              if (!(dynamic_cast<AbstractModel*>(artifactMap->get(BUILD_MODEL_ENTRY_NAME)) != 0))
              {
                throw InvalidFormatException("Missing the build model!");
              }

              ParserType modelType = getParserType();

              if (modelType != 0)
              {
                if (CHUNKING::equals(modelType))
                {
                  if (artifactMap->get(ATTACH_MODEL_ENTRY_NAME) != 0)
                      throw InvalidFormatException("attachModel must be null for chunking parser!");
                }
                else if (TREEINSERT::equals(modelType))
                {
                  if (!(dynamic_cast<AbstractModel*>(artifactMap->get(ATTACH_MODEL_ENTRY_NAME)) != 0))
                    throw InvalidFormatException("attachModel must not be null!");
                }
                else
                {
                  throw InvalidFormatException("Unkown ParserType!");
                }
              }
              else
              {
                throw InvalidFormatException("Missing the parser type property!");
              }

              if (!(dynamic_cast<AbstractModel*>(artifactMap->get(CHECK_MODEL_ENTRY_NAME)) != 0))
              {
                throw InvalidFormatException("Missing the check model!");
              }

              if (!(dynamic_cast<POSModel*>(artifactMap->get(PARSER_TAGGER_MODEL_ENTRY_NAME)) != 0))
              {
                throw InvalidFormatException("Missing the tagger model!");
              }

              if (!(dynamic_cast<ChunkerModel*>(artifactMap->get(CHUNKER_TAGGER_MODEL_ENTRY_NAME)) != 0))
              {
                throw InvalidFormatException("Missing the chunker model!");
              }

              if (!(dynamic_cast<HeadRules*>(artifactMap->get(HEAD_RULES_MODEL_ENTRY_NAME)) != 0))
              {
                throw InvalidFormatException("Missing the head rules!");
              }
            }
Exemplo n.º 6
0
unsigned int binary_to_uint(std::string s) {
    if (s.size() == 0)
        throw InvalidFormatException("Should at least one char, e.g. 0");
   
    unsigned int sum = 0;
    unsigned int mul = 1;

    for (int i = s.size() - 1; i >= 0; --i) {
        if (s[i] != '0' && s[i] != '1') 
            throw InvalidFormatException("binary literal should be 0 or 1");
        sum += mul*char_to_uint(s[i]);
        mul *= 2;
    }
    return sum;

}
Exemplo n.º 7
0
unsigned int char_to_uint(char c) {
    switch(c) {
        case '0' : return 0;
        case '1' : return 1;
        case '2' : return 2;
        case '3' : return 3;
        case '4' : return 4;
        case '5' : return 5;
        case '6' : return 6;
        case '7' : return 7;
        case '8' : return 8;
        case '9' : return 9;
        case 'a' :
        case 'A' :
            return 10;
        case 'b' : 
        case 'B' : 
            return 11;
        case 'c' : 
        case 'C' : 
            return 12;
        case 'd' : 
        case 'D' : 
            return 13;
        case 'e' : 
        case 'E' : 
            return 14;
        case 'f' : 
        case 'F' : 
            return 15;
        default:
            break; 
    }
    throw InvalidFormatException("Character not one of the choices");
}
Exemplo n.º 8
0
void BgzfReader::nextBlock() {
    uInt oldAvailOut = stream.avail_out;
    stream.avail_out = 0;
    while(true) {
        if(0 == stream.avail_in) {
            qint64 returnedValue = ioAdapter.readBlock(buffer, sizeof(buffer));
            if(-1 == returnedValue) {
                coreLog.error(QString("in BgzfReader::nextBlock, failed to read %1 bytes from ioAdapter, after %2 bytes already read. %3")
                              .arg(sizeof(buffer))
                              .arg(ioAdapter.bytesRead())
                              .arg(ioAdapter.errorString()));
                throw IOException(BAMDbiPlugin::tr("Can't read input"));
            } else if(0 == returnedValue) {
                endOfFile = true;
                break;
            } else {
                stream.avail_in = returnedValue;
                stream.next_in = (Bytef *)buffer;
            }
        }
        int returnedValue = inflate(&stream, Z_SYNC_FLUSH);
        if(Z_STREAM_END == returnedValue) {
            headerOffset = ioAdapter.bytesRead() - stream.avail_in;
            inflateReset(&stream);
        } else if(Z_BUF_ERROR == returnedValue) {
            break;
        } else if(Z_OK != returnedValue) {
            coreLog.error(QString("in BgzfReader::nextBlock, failed to decompress %1 bytes, after %2 raw bytes already read")
                          .arg(sizeof(buffer))
                          .arg(ioAdapter.bytesRead()));
            throw InvalidFormatException(BAMDbiPlugin::tr("Can't decompress data"));
        }
    }
    stream.avail_out = oldAvailOut;
}
Exemplo n.º 9
0
bool RecordingDevice::start(int samples, int sampleRate, int bitDepth, int channels)
{
	ALenum format = Audio::getFormat(bitDepth, channels);
	if (format == AL_NONE)
		throw InvalidFormatException(channels, bitDepth);

	if (samples <= 0)
		throw love::Exception("Invalid number of samples.");

	if (sampleRate <= 0)
		throw love::Exception("Invalid sample rate.");

	if (isRecording())
		stop();

	device = alcCaptureOpenDevice(name.c_str(), sampleRate, format, samples);
	if (device == nullptr)
		return false;

	alcCaptureStart(device);

	this->samples = samples;
	this->sampleRate = sampleRate;
	this->bitDepth = bitDepth;
	this->channels = channels;

	return true;
}
Exemplo n.º 10
0
QJsonDocument Api::get(const QString& path, CancellationToken cancellationToken) const
{
    qInfo() << "Executing GET " << path;

    ApiConnectionSettings connectionSettings = defaultConnectionSettings();
    ApiConnectionStrategy strategy(connectionSettings, Config::minConnectionTimeoutMsec, Config::maxConnectionTimeoutMsec);

    QBuffer buffer;
    buffer.open(QIODevice::WriteOnly);

    if (!strategy.execute(m_dataSource, path, buffer, cancellationToken))
    {
        throw ApiConnectionError("Failed to connect to the api.");
    }

    auto data = buffer.data();

    QJsonParseError parseError;
    auto doc = QJsonDocument::fromJson(data, &parseError);

    if (parseError.error != QJsonParseError::NoError)
    {
        throw InvalidFormatException(parseError.errorString());
    }

    return doc;
}
Exemplo n.º 11
0
unsigned int hex_to_uint(std::string s) {
    if (s.size() == 0)
        throw InvalidFormatException("Should at least one char, e.g. 0");
    
    unsigned int sum = 0;
    unsigned int mul = 1;

    for (int i = s.size() - 1; i >= 0; --i) {
        sum += mul*char_to_uint(s[i]);
        mul *= 16;
    }
    return sum;
}
Exemplo n.º 12
0
            void TokenNameFinderModel::validateArtifactMap() throw(InvalidFormatException)
            {
              BaseModel::validateArtifactMap();

              if (dynamic_cast<AbstractModel*>(artifactMap->get(MAXENT_MODEL_ENTRY_NAME)) != 0)
              {
                AbstractModel *model = static_cast<AbstractModel*>(artifactMap->get(MAXENT_MODEL_ENTRY_NAME));
                isModelValid(model);
              }
              else
              {
                throw InvalidFormatException("Token Name Finder model is incomplete!");
              }
            }
Exemplo n.º 13
0
QStringList Api::getContentUrls(const QString& appSecret, int versionId, CancellationToken cancellationToken) const
{
    qInfo() << "Getting the content urls for app " << appSecret << " version " << versionId;
    auto path = QString("1/apps/%1/versions/%2/content_urls")
            .arg(appSecret).arg(versionId);

    QJsonDocument document = get(path, cancellationToken);

    QStringList contentUrls;

    if (!document.isArray())
    {
        throw InvalidFormatException("Expected document root to be array");
    }

    auto arr = document.array();

    for (auto item : arr)
    {
        if (!item.isObject())
        {
            throw InvalidFormatException("Expected array item to be object");
        }

        QJsonObject obj = item.toObject();

        if (!obj.contains("url"))
        {
            throw InvalidFormatException("Did not contain the 'url' field");
        }

        contentUrls.push_back(obj["url"].toString());
    }

    return contentUrls;
}
Exemplo n.º 14
0
qint64 BgzfReader::read(char *buff, qint64 maxSize) {
    if(0 == maxSize) {
        return 0;
    }
    stream.next_out = (Bytef *)buff;
    stream.avail_out = maxSize;
    while(stream.avail_out > 0) {
        if(0 == stream.avail_in) {
            qint64 returnedValue = ioAdapter.readBlock(buffer, sizeof(buffer));
            if(-1 == returnedValue) {
                coreLog.error(QString("in BgzfReader::read, failed to read %1 bytes from ioAdapter, after %2 bytes already read. %3")
                              .arg(sizeof(buffer))
                              .arg(ioAdapter.bytesRead())
                              .arg(ioAdapter.errorString()));
                throw IOException(BAMDbiPlugin::tr("Can't read input"));
            } else if(0 == returnedValue) {
                endOfFile = true;
                break;
            } else {
                stream.avail_in = returnedValue;
                stream.next_in = (Bytef *)buffer;
            }
        }
        int returnedValue = inflate(&stream, Z_SYNC_FLUSH);
        if(Z_STREAM_END == returnedValue) {
            nextBlock();
        } else if(Z_OK != returnedValue) {
            coreLog.error(QString("in BgzfReader::read, failed to decompress %1 bytes, after %2 raw bytes already read")
                          .arg(sizeof(buffer))
                          .arg(ioAdapter.bytesRead()));
            throw InvalidFormatException(BAMDbiPlugin::tr("Can't decompress data"));
        }
    }
    if(0 == stream.avail_in) {
        nextBlock();
    }
    qint64 bytesRead = maxSize - stream.avail_out;
    return bytesRead;
}
Exemplo n.º 15
0
unsigned int uint_to_char(unsigned int val) {
    switch(val) {
        case 0 : return '0';
        case 1 : return '1';
        case 2 : return '2';
        case 3 : return '3';
        case 4 : return '4';
        case 5 : return '5';
        case 6 : return '6';
        case 7 : return '7';
        case 8 : return '8';
        case 9 : return '9';
        case 10 : return 'A';
        case 11 : return 'B';
        case 12 : return 'C';
        case 13 : return 'D';
        case 14 : return 'E';
        case 15 : return 'F';
        default : break;
    }

    throw InvalidFormatException("Overflow for input");
}
Exemplo n.º 16
0
void PFPFile::load(FileObject &ff)
/*!\brief PFP-File laden
 *
 * Mit dieser Funktion wird ein PFP-File in die Klasse geladen. Dabei wird zuerst der Header geladen
 * und überprüft, ob es sich um ein gültiges PFP-File handelt. Dann wird die virtuelle Funktion
 * PFPFile::LoadRequest mit ID, Haupt- und Unterversion als Parameter aufgerufen. Liefert diese
 * nicht true (1) zurück, wird der Ladevorgang abgebrochen. Andernfalls wird fortgeführt
 * und geprüft, ob der
 * Datenbereich komprimiert ist und gegebenenfalls dekomprimiert. Erst danach werden die
 * einzelnen Chunks eingelesen. Kommt es dabei zu Fehlern durch ungültige Chunks, werden diese
 * ignoriert und die Funktion gibt den Fehlercode 434 zurück.
 *
 * \param ff Pointer auf eine CFile-Klasse, mit der die einzulesende Datei geöffnet wurde.
 * \returns Konnte die Datei fehlerfrei eingelesen werden, gibt die Funktion true (1) zurück,
 * im Fehlerfall false (0). Ein entsprechender Fehlercode wird gesetzt.
 *
 * \remarks
 * Vor dem Laden der Datei wird die Funktion PFPFile::Clear aufgerufen, so dass eventuell vorher
 * vorhandene Daten verloren gehen.
 *
 * \since Version 6.1.0
 */
{
	const char *p;
	try {
		p=ff.map(0,24);
	} catch (OverflowException &) {
		throw InvalidFormatException();
	}
	if (strncmp(p,"PFP-File",8)!=0) throw InvalidFormatException();
	if (Peek8(p+8)!=3) throw InvalidFormatException();
	size_t z,fsize;
	// Wir haben ein gültiges PFP-File, aber dürfen wir es auch laden?
	char tmpid[5];
	tmpid[4]=0;
	strncpy(tmpid,p+10,4);
	int t1,t2;
	t1=Peek8(p+15);
	t2=Peek8(p+14);
	if (!loadRequest(tmpid,t1,t2)) {
		throw AccessDeniedByInstanceException();
	}
	clear();
	id.set(p+10,4);
	mainversion=Peek8(p+15);
	subversion=Peek8(p+14);
	comp=(Compression::Algorithm)Peek8(p+16);
	size_t hsize=Peek8(p+9);
	char *u=NULL;
	if (comp) {
		p=(char*)ff.map(hsize,8);
		if (!p) throw ReadException();
		size_t sizeunk=Peek32(p);
		size_t sizecomp=Peek32(p+4);
		p=ff.map(hsize+8,sizecomp);
		if (!p) throw ReadException();
		u=(char*)malloc(sizeunk+1);
		if (!u) throw OutOfMemoryException();
		size_t dstlen=sizeunk;
		Compression c;
		try {
			c.init(comp);
			c.uncompress(u,&dstlen,p,sizecomp);
		} catch (...) {
			free(u);
			clear();
			throw;
		}
		if (dstlen!=sizeunk) {
			free(u);
			clear();
			throw DecompressionFailedException();
		}
		u[dstlen]=0;
		p=u;
		fsize=dstlen;
	} else {
		p=ff.map();
		p+=hsize;
		fsize=ff.size()-hsize;
	}
	// Wir haben nun den ersten Chunk ab Pointer p
	z=0;
	String Chunkname;
	try {
		size_t size=0;
		while ((z+=size)<fsize) {
			size=Peek32(p+z+4);
			if (strncmp(p+z,"ENDF",4)==0) break;
			if (!size) break;
			// Falls z+size über das Ende der Datei geht, stimmt mit diesem Chunk was nicht
			if (z+size>fsize) break;
			PFPChunk *chunk=new PFPChunk;
			if (!chunk) throw OutOfMemoryException();
			Chunkname.set(p+z,4);
			chunk->setName(Chunkname);
			chunk->setData(p+z+8,size-8);
			addChunk(chunk);
		}
	} catch (...) {
		if (u) free(u);
		clear();
		throw;
	}
	if (u) free(u);
}