Ejemplo n.º 1
0
void WAVStream::readFormatSubchunk(int size)
{
	format_.audioFormat = readInt16();
	format_.channelCount = readInt16();
	format_.sampleRate = readInt32();
	format_.byteRate = readInt32();
	format_.blockAlign = readInt16();
	format_.bitsPerSample = readInt16();
	
	streamInfo_.sampleRate = format_.sampleRate;
}
Ejemplo n.º 2
0
int WAVStream::readSubchunk()
{
	string subchunkId = readString(4);
	int size = readInt32();
	
	//cerr << "CHUNK " << subchunkId << ", SIZE = " << size << endl;
	
	if (subchunkId.compare(WAVFormat::FORMAT_SUBCHUNK_ID) == 0) {
		readFormatSubchunk(size);
	} else if (subchunkId.compare(WAVFormat::INF1_SUBCHUNK_ID) == 0) {
		readInf1Subchunk(size);
	} else if (subchunkId.compare(WAVFormat::DATA_SUBCHUNK_ID) == 0) {
		if (!dataRead_) {
			startStream();
			//if (backend_.isNotNull())
			//	backend_->startStream(streamInfo_);
			dataRead_ = true;
		}
		readDataSubchunk(size);
	} else {
		readUnknownSubchunk(size);
	}
	
	return size + 4;
}
Ejemplo n.º 3
0
int32_t BinaryReader::readInt32(const BinaryReader::BigEndian&)
{
    const int32_t value = readInt32(BinaryReader::LittleEndian());
    const int32_t swapped = swapEndian(value);

    return swapped;
}
Ejemplo n.º 4
0
//------------------------------------------------------------------------
bool PresetFile::readChunkList ()
{
	seekTo (0);
	entryCount = 0;

	char8 classString[kClassIDSize + 1] = {0};

	// Read header
	int32 version = 0;
	TSize listOffset = 0;
	if (!(readEqualID (getChunkID (kHeader)) &&
		 readInt32 (version) &&
		 verify (stream->read (classString, kClassIDSize)) &&
		 readSize (listOffset) &&
		 listOffset > 0 &&
		 seekTo (listOffset)))
		return false;

	classID.fromString (classString);

	// Read list
	int32 count = 0;
	if (!readEqualID (getChunkID (kChunkList)))
		return false;
	if (!readInt32 (count))
		return false;

	if (count > kMaxEntries)
		count = kMaxEntries;

	for (int32 i = 0; i < count; i++)
	{
		Entry& e = entries[i];
		if (!(readID (e.id) &&
			 readSize (e.offset) &&
			 readSize (e.size)))
			break;

		entryCount++;
	}

	return entryCount > 0;
}
Ejemplo n.º 5
0
void BaseSerializedObj::readInt32Array(int32_t** o)
{
    uint64_t size = readUInt64();
    *o = (int32_t *) malloc(size*byteSize_writeInt32);
    uint64_t i = 0;
    while(i != size)
    {
        (*o)[i] = readInt32();
        i++;
    }
}
Ejemplo n.º 6
0
void BaseSerializedObj::readChars(char** p)
{
    int length = readInt32();
    *p = (char*) malloc(length+1);
    int i = 0;
    while(i != length)
    {
        (*p)[i] = readByte();
        i++;
    }
    (*p)[length] = '\0';
}
Ejemplo n.º 7
0
std::string BaseSerializedObj::readString()
{
    int length = readInt32();
    std::string r = "";
    int i = 0;
    while(i != length)
    {
        r.push_back(readByte());
        i++;
    }
    return r;
}
Ejemplo n.º 8
0
//------------------------------------------------------------------------
bool PresetFile::getUnitProgramListID (int32& unitProgramListID)
{
	const Entry* e = getEntry (kProgramData);
	if (e && seekTo (e->offset))
	{
		if (readInt32 (unitProgramListID))
		{
			return true;
		}
	}
	return false;
}
Ejemplo n.º 9
0
int WaveReader::readSample(int bytes) {
	switch (bytes) {
		case 1:
			return readInt8();
		case 2:
			return readInt16();
		case 4:
			return readInt32();
	}

	return 0;
}
Ejemplo n.º 10
0
WaveInfo WaveReader::readHeader() {
	int  chunkId   = 0;
	bool dataChunk = false;

	WaveInfo info;

	while (!dataChunk) {
	    chunkId = readInt32();
	    switch (chunkId) {
		    case FORMAT:
		    	//printf("Format\n");
		        info.formatSize = readInt32();
		        info.format = readInt16();
		        info.channels = readInt16();
		        info.sampleRate = readInt32();
		        info.bitsPerSecond = readInt32();
		        info.formatBlockAlign = readInt16();
		        info.bitDepth = readInt16();

		        if (info.formatSize == 18) {
		            int extraData = readInt16();
		            fseek(mWavFile, extraData, SEEK_CUR);
		        }
		        break;

		    case RIFF_HEADER:
		    	//printf("Riff Header\n");
		        info.headerId = chunkId;
		        info.memSize = readInt32();
		        info.riffStyle = readInt32();
		        break;

		    case DATA:
		    	//printf("Data\n");
		        dataChunk = true;
		        info.dataSize = readInt32();
		        break;

		    default:
		        int skipSize = readInt32();
		        //printf("Skip Size = %d\n", skipSize);
		        fseek(mWavFile, skipSize, SEEK_CUR);
		        break;
	    }
	}

	return info;
}
Ejemplo n.º 11
0
//------------------------------------------------------------------------
bool PresetFile::restoreProgramData (IUnitData* unitData, UnitID* unitId)
{
	const Entry* e = getEntry (kProgramData);
	UnitID savedUnitID = -1;
	if (e && seekTo (e->offset))
	{
		if (readInt32 (savedUnitID))
		{
			if (unitId && *unitId != savedUnitID)
				return false;

			int32 alreadyRead = sizeof (int32);
			ReadOnlyBStream* readOnlyBStream = new ReadOnlyBStream (stream, e->offset + alreadyRead, e->size - alreadyRead);
			FReleaser readOnlyStreamReleaser (readOnlyBStream);
			return (unitData && verify (unitData->setUnitData (savedUnitID, readOnlyBStream)));
		}
	}
	return false;
}
Ejemplo n.º 12
0
//------------------------------------------------------------------------
bool PresetFile::restoreProgramData (IUnitInfo* unitInfo, int32 unitProgramListID, int32 programIndex)
{
	const Entry* e = getEntry (kProgramData);
	int32 savedProgramListID = -1;
	if (e && seekTo (e->offset))
	{
		if (readInt32 (savedProgramListID))
		{
			if (unitProgramListID != savedProgramListID)
				return false;

			int32 alreadyRead = sizeof (int32);
			ReadOnlyBStream* readOnlyBStream = new ReadOnlyBStream (stream, e->offset + alreadyRead, e->size - alreadyRead);
			FReleaser readOnlyStreamReleaser (readOnlyBStream);
			return (unitInfo && unitInfo->setUnitProgramData (unitProgramListID, programIndex, readOnlyBStream));
		}
	}
	return false;
}
Ejemplo n.º 13
0
//------------------------------------------------------------------------
bool PresetFile::restoreProgramData (IProgramListData* programListData, ProgramListID* programListID, int32 programIndex)
{
	const Entry* e = getEntry (kProgramData);
	ProgramListID savedProgramListID = -1;
	if (e && seekTo (e->offset))
	{
		if (readInt32 (savedProgramListID))
		{
			if (programListID && *programListID != savedProgramListID)
				return false;

			int32 alreadyRead = sizeof (int32);
			ReadOnlyBStream* readOnlyBStream = new ReadOnlyBStream (stream, e->offset + alreadyRead, e->size - alreadyRead);
			FReleaser readOnlyBStreamReleaser (readOnlyBStream);
			return programListData && verify (programListData->setProgramData (savedProgramListID, programIndex, readOnlyBStream));
		}
	}
	return false;
}
Ejemplo n.º 14
0
bool IfdFileContainer::_locateDirs(void)
{
    if (!locateDirsPreHook()) {
        return false;
    }
    Trace(DEBUG1) << "_locateDirs()\n";
    if (m_endian == ENDIAN_NULL) {
        char buf[4];
        m_file->seek(m_offset, SEEK_SET);
        m_file->read(buf, 4);
        m_endian = isMagicHeader(buf, 4);
        if (m_endian == ENDIAN_NULL) {
            // FIXME set error code
            return false;
        }
    }
    m_file->seek(m_offset + 4, SEEK_SET);
    int32_t dir_offset = 0;
    readInt32(m_file, dir_offset);
    m_dirs.clear();
    do {
        if (dir_offset != 0) {
            //					std::cerr.setf(std::ios_base::hex,
            // std::ios_base::basefield);
            Trace(DEBUG1) << "push offset =0x" << dir_offset << "\n";

            // we assume the offset is relative to the begining of
            // the IFD.
            IfdDir::Ref dir(
                std::make_shared<IfdDir>(m_offset + dir_offset, *this));
            m_dirs.push_back(dir);

            //					std::cerr.setf((std::ios_base::fmtflags)0,
            // std::ios_base::basefield);

            dir_offset = dir->nextIFD();
        }
    } while (dir_offset != 0);

    Trace(DEBUG1) << "# dir found = " << m_dirs.size() << "\n";
    return (m_dirs.size() != 0);
}
Ejemplo n.º 15
0
void WAVStream::run()
{
	//char chunkID[5];
	//chunkID[4] = 0;
	//input_->getStream()->read(chunkID, 4);
	
	//cout << "CHUNK ID: " << chunkID << endl;
	
	streamInfo_ = StreamInfo();
	
	string chunkId = readString(4);
	if (chunkId.compare(WAVFormat::CHUNK_ID) != 0) {
		cerr << "ERROR: Invalid chunk ID. Stream may not be in WAV format." << endl;
		return;
	}
	
	int32_t chunkSize = readInt32();
	
	string chunkFormat = readString(4);
	if (chunkFormat.compare(WAVFormat::CHUNK_FORMAT) != 0) {
		cerr << "ERROR: Invalid chunk format. Stream may not be in WAV format." << endl;
		return;
	}
	
	chunkSize -= 4;
	
	formatRead_ = false;
	dataRead_ = false;
	
	dataInfo_ = DataInfo();
	
	while (chunkSize > 0) {
		chunkSize -= readSubchunk();
	}
	
	endStream();
	//if (backend_.isNotNull())
	//	backend_->endStream();
}
Ejemplo n.º 16
0
size_t IfdFileContainer::getDirectoryDataSize()
{
    // TODO move to IFDirectory
    Trace(DEBUG1) << "getDirectoryDataSize()"
                  << "\n";
    off_t dir_offset = m_current_dir->offset();
    // FIXME check error
    Trace(DEBUG1) << "offset = " << dir_offset
                  << " m_numTags = " << m_current_dir->numTags() << "\n";
    off_t begin = dir_offset + 2 + (m_current_dir->numTags() * 12);

    Trace(DEBUG1) << "begin = " << begin << "\n";

    m_file->seek(begin, SEEK_SET);
    begin += 2;
    int32_t nextIFD;
    readInt32(m_file, nextIFD);
    Trace(DEBUG1) << "nextIFD = " << nextIFD << "\n";
    if (nextIFD == 0) {
        // FIXME not good
    }
    return nextIFD - begin;
}
Ejemplo n.º 17
0
BeingId MessageIn::readBeingId(const char *const str)
{
    return fromInt(readInt32(str), BeingId);
}
Ejemplo n.º 18
0
string psoCat::odbcFieldToStr( uint32_t length )
{
   psoFieldDefinition * fieldODBC;
   int numFields, i;
   string outStr;
   
   fieldODBC = (psoFieldDefinition *) fieldDef;
   numFields = fieldDefLength / sizeof(psoFieldDefinition);
   
   psoaGetFieldOffsets( fieldODBC, numFields, fieldOffsets );

   for ( i = 0; i < numFields; ++i ) {
      string s;
      
      switch( fieldODBC[i].type ) {

      case PSO_TINYINT:
         s = readInt8( &buffer[fieldOffsets[i]] );
         break;

      case PSO_SMALLINT:
         s = readInt16( &buffer[fieldOffsets[i]] );
         break;

      case PSO_INTEGER:
         s = readInt32( &buffer[fieldOffsets[i]] );
         break;

      case PSO_BIGINT:
         s = readInt64( &buffer[fieldOffsets[i]] );
         break;

      case PSO_BINARY:
         readBinary( s,
                     fieldODBC[i].vals.length,
                     &buffer[fieldOffsets[i]] );
         break;

      case PSO_CHAR:
         readString( s,
                     fieldODBC[i].vals.length,
                     &buffer[fieldOffsets[i]] );
         break;

      case PSO_NUMERIC:
         s = readDecimal( fieldODBC[i].vals.decimal.precision,
                          fieldODBC[i].vals.decimal.scale,
                          &buffer[fieldOffsets[i]] );
         break;

      case PSO_VARCHAR:
      case PSO_LONGVARCHAR:
         readString( s,
                     length - fieldOffsets[i],
                     &buffer[fieldOffsets[i]] );
         break;
      case PSO_VARBINARY:
      case PSO_LONGVARBINARY:
         readBinary( s,
                     length - fieldOffsets[i],
                     &buffer[fieldOffsets[i]] );
         break;

      case PSO_REAL:
         s = readFloat32( &buffer[fieldOffsets[i]] );
         break;

      case PSO_DOUBLE:
         s = readFloat64( &buffer[fieldOffsets[i]] );
         break;
      
      case PSO_DATE:
         s = readDate( &buffer[fieldOffsets[i]] );
         break;

      case PSO_TIME:
         s = readTime( &buffer[fieldOffsets[i]] );
         break;

      case PSO_TIMESTAMP:
         s = readTimeStamp( &buffer[fieldOffsets[i]] );
         break;
      }
      outStr += s;
      if ( i < numFields-1) outStr += ", ";
   }
   
   return outStr;
}
Ejemplo n.º 19
0
        void initFileObject(lua_State* L)
        {
            luaL_newmetatable(L, meta<File>());
            // Duplicate the metatable on the stack.
            lua_pushvalue(L, -1);
            // metatable.__index = metatable
            lua_setfield(L, -2, "__index");

            // Put the members into the metatable.
            const luaL_Reg functions[] = {
                {"__gc", [](lua_State* L) { return script::wrapped<File>(L, 1)->gc(L); }},
                {"__index", [](lua_State* L) { return script::wrapped<File>(L, 1)->index(L); }},
                {"__newindex", [](lua_State* L) { return script::wrapped<File>(L, 1)->newindex(L); }},
                {"__tostring", [](lua_State* L) { return script::wrapped<File>(L, 1)->tostring(L); }},
                {"__pairs", [](lua_State* L) { return script::wrapped<File>(L, 1)->pairs(L); }},
                {"close", [](lua_State* L)
                {
                    auto file = script::ptr<File>(L, 1);
                    file->close();
                    return 0;
                }},
                {"readUnsigned8", [](lua_State* L)
                {
                    auto file = script::ptr<File>(L, 1);

                    uint8_t value;
                    if(file->readUnsigned8(value))
                    {
                        script::push(L, value);
                        return 1;
                    }
                    return 0;
                }},
                {"readUnsigned16", [](lua_State* L)
                {
                    auto file = script::ptr<File>(L, 1);

                    uint16_t value;
                    if(file->readUnsigned16(value))
                    {
                        script::push(L, value);
                        return 1;
                    }
                    return 0;
                }},
                {"readUnsigned32", [](lua_State* L)
                {
                    auto file = script::ptr<File>(L, 1);

                    uint32_t value;
                    if(file->readUnsigned32(value))
                    {
                        script::push(L, value);
                        return 1;
                    }
                    return 0;
                }},
                {"readInt8", [](lua_State* L)
                {
                    auto file = script::ptr<File>(L, 1);

                    int8_t value;
                    if(file->readInt8(value))
                    {
                        script::push(L, value);
                        return 1;
                    }
                    return 0;
                }},
                {"readInt16", [](lua_State* L)
                {
                    auto file = script::ptr<File>(L, 1);

                    int16_t value;
                    if(file->readInt16(value))
                    {
                        script::push(L, value);
                        return 1;
                    }
                    return 0;
                }},
                {"readInt32", [](lua_State* L)
                {
                    auto file = script::ptr<File>(L, 1);

                    int32_t value;
                    if(file->readInt32(value))
                    {
                        script::push(L, value);
                        return 1;
                    }
                    return 0;
                }},
                {"readFloat", [](lua_State* L)
                {
                    auto file = script::ptr<File>(L, 1);

                    float value;
                    if(file->readFloat(value))
                    {
                        script::push(L, value);
                        return 1;
                    }
                    return 0;
                }},
                {"readDouble", [](lua_State* L)
                {
                    auto file = script::ptr<File>(L, 1);

                    double value;
                    if(file->readDouble(value))
                    {
                        script::push(L, value);
                        return 1;
                    }
                    return 0;
                }},
                {"readString", [](lua_State* L)
                {
                    auto file = script::ptr<File>(L, 1);
                    auto blockSize = script::get<int>(L, 2);

                    std::string buffer(blockSize, 0);
                    if(file->readString(buffer))
                    {
                        lua_pushlstring(L, buffer.data(), buffer.size());
                        return 1;
                    }
                    return 0;
                }},
                {"readLine", [](lua_State* L)
                {
                    auto file = script::ptr<File>(L, 1);

                    std::string value;
                    if(file->readLine(value))
                    {
                        script::push(L, value.c_str());
                        return 1;
                    }
                    return 0;
                }},
                {"readFully", [](lua_State* L)
                {
                    auto file = script::ptr<File>(L, 1);

                    // Get current position.
                    auto pos = file->tell();
                    if(pos == -1)
                    {
                        return 0;
                    }

                    // Length to read = position of end - current.
                    auto length = 0;
                    if(!file->seek(pos, FileSeekMode::End))
                    {
                        return 0;
                    }
                    length = file->tell() - pos;
                    if(!file->seek(pos, FileSeekMode::Start))
                    {
                        return 0;
                    }

                    // Read the entire file into a string.
                    std::string buf(length, 0);
                    if(file->readString(buf))
                    {
                        lua_pushlstring(L, buf.data(), buf.size());
                        return 1;
                    }
                    return 0;
                }},
                {"writeUnsigned8", [](lua_State* L)
                {
                    auto file = script::ptr<File>(L, 1);
                    auto value = script::get<int>(L, 2);

                    script::push(L, file->writeUnsigned8(value));
                    return 1;
                }},
                {"writeUnsigned16", [](lua_State* L)
                {
                    auto file = script::ptr<File>(L, 1);
                    auto value = script::get<int>(L, 2);

                    script::push(L, file->writeUnsigned16(value));
                    return 1;
                }},
                {"writeUnsigned32", [](lua_State* L)
                {
                    auto file = script::ptr<File>(L, 1);
                    auto value = script::get<int>(L, 2);

                    script::push(L, file->writeUnsigned32(value));
                    return 1;
                }},
                {"writeInt8", [](lua_State* L)
                {
                    auto file = script::ptr<File>(L, 1);
                    auto value = script::get<int>(L, 2);

                    script::push(L, file->writeInt8(value));
                    return 1;
                }},
                {"writeInt16", [](lua_State* L)
                {
                    auto file = script::ptr<File>(L, 1);
                    auto value = script::get<int>(L, 2);

                    script::push(L, file->writeInt16(value));
                    return 1;
                }},
                {"writeInt32", [](lua_State* L)
                {
                    auto file = script::ptr<File>(L, 1);
                    auto value = script::get<int>(L, 2);

                    script::push(L, file->writeInt32(value));
                    return 1;
                }},
                {"writeFloat", [](lua_State* L)
                {
                    auto file = script::ptr<File>(L, 1);
                    auto value = script::get<double>(L, 2);

                    script::push(L, file->writeFloat((float) value));
                    return 1;
                }},
                {"writeDouble", [](lua_State* L)
                {
                    auto file = script::ptr<File>(L, 1);
                    auto value = script::get<double>(L, 2);

                    script::push(L, file->writeDouble(value));
                    return 1;
                }},
                {"writeString", [](lua_State* L)
                {
                    auto file = script::ptr<File>(L, 1);
                    size_t length = 0;
                    const char* buffer = luaL_checklstring(L, 2, &length);
                    std::string value(buffer, buffer + length);
                    script::push(L, file->writeString(value));
                    return 1;
                }},
                {"writeLine", [](lua_State* L)
                {
                    auto file = script::ptr<File>(L, 1);
                    size_t length = 0;
                    const char* buffer = luaL_checklstring(L, 2, &length);
                    std::string value(buffer, buffer + length);
                    script::push(L, file->writeLine(value));
                    return 1;
                }},
                {"tell", [](lua_State* L)
                {
                    auto file = script::ptr<File>(L, 1);
                    script::push(L, int(file->tell()));
                    return 1;
                }},
                {"seek", [](lua_State* L)
                {
                    auto file = script::ptr<File>(L, 1);
                    auto position = script::get<int>(L, 2);
                    auto mode = FileSeekMode(script::get<int>(L, 3));
                    script::push(L, file->seek(position, mode));
                    return 1;
                }},
                {"flush", [](lua_State* L)
                {
                    auto file = script::ptr<File>(L, 1);
                    file->flush();
                    return 0;
                }},
                {nullptr, nullptr},
            };
            luaL_setfuncs(L, functions, 0);

            lua_pop(L, 1);
                
            // Push plum namespace.
            lua_getglobal(L, "plum");

            // plum.File = <function create>
            script::push(L, "File");
            lua_pushcfunction(L, [](lua_State* L)
            {
                auto filename = script::get<const char*>(L, 1);
                auto mode = FileOpenMode(script::get<int>(L, 2));
                auto f = new File(filename, mode);
                // Failure.
                if(!f->isActive())
                {    
                    delete f;
                    return 0;
                }

                script::push(L, f, LUA_NOREF);
                return 1;
            });
            lua_settable(L, -3);

            // Pop plum namespace.
            lua_pop(L, 1);
        }
Ejemplo n.º 20
0
float BaseSerializedObj::readFloat()
{
    unsigned char* a = (unsigned char* ) readInt32();
    float r = *(float *) &a;
    return r;
}
Ejemplo n.º 21
0
/*
 * Internal static function for decoding of the header fields.
 */
static int decodeHeader(GTPublicationsFile *pubfile)
{
	size_t data_block_size;
	size_t hash_data_block_size;

	assert(sizeof(int) >= 4);
	assert(sizeof(long long) >= 8);

	if (pubfile->data_length < 1) {
		return GT_INVALID_FORMAT;
	}

	pubfile->version = readUInt16(pubfile->data +
			GTPublicationsFile_HeaderOffset_version);

	if (pubfile->version != GTPublicationsFile_CurrentVersion) {
		return GT_UNSUPPORTED_FORMAT;
	}

	if (pubfile->data_length < GTPublicationsFile_HeaderLength) {
		return GT_INVALID_FORMAT;
	}

	pubfile->first_publication_ident = readInt64(pubfile->data +
			GTPublicationsFile_HeaderOffset_firstPublicationIdent);
	pubfile->data_block_begin = readInt32(pubfile->data +
			GTPublicationsFile_HeaderOffset_dataBlockBegin);
	pubfile->publication_cell_size = readUInt16(pubfile->data +
			GTPublicationsFile_HeaderOffset_publicationCellSize);
	pubfile->number_of_publications = readInt32(pubfile->data +
			GTPublicationsFile_HeaderOffset_numberOfPublications);
	pubfile->key_hashes_begin = readInt32(pubfile->data +
			GTPublicationsFile_HeaderOffset_keyHashesBegin);
	pubfile->key_hash_cell_size = readUInt16(pubfile->data +
			GTPublicationsFile_HeaderOffset_keyHashCellSize);
	pubfile->number_of_key_hashes = readUInt16(pubfile->data +
			GTPublicationsFile_HeaderOffset_numberOfKeyHashes);
	pubfile->pub_reference_begin = readInt32(pubfile->data +
			GTPublicationsFile_HeaderOffset_pubReferenceBegin);
	pubfile->signature_block_begin = readInt32(pubfile->data +
			GTPublicationsFile_HeaderOffset_signatureBlockBegin);

	if (pubfile->data_block_begin < GTPublicationsFile_HeaderLength ||
			pubfile->data_block_begin > pubfile->data_length) {
		return GT_INVALID_FORMAT;
	}

	if (pubfile->key_hashes_begin < pubfile->data_block_begin ||
			pubfile->key_hashes_begin > pubfile->data_length) {
		return GT_INVALID_FORMAT;
	}

	if (pubfile->pub_reference_begin < pubfile->key_hashes_begin ||
			pubfile->pub_reference_begin > pubfile->data_length) {
		return GT_INVALID_FORMAT;
	}

	if (pubfile->signature_block_begin < pubfile->pub_reference_begin ||
			pubfile->signature_block_begin > pubfile->data_length) {
		return GT_INVALID_FORMAT;
	}

	data_block_size = pubfile->key_hashes_begin - pubfile->data_block_begin;
	hash_data_block_size =
		pubfile->signature_block_begin - pubfile->key_hashes_begin;

	/* Using integer division instead of multiply ensures that there will
	 * be no overflows and thus no false positives in case of invalid values
	 * of publication_cell_size or number_of_publications. */
	if (data_block_size / pubfile->publication_cell_size <
			pubfile->number_of_publications) {
		return GT_INVALID_FORMAT;
	}

	if (hash_data_block_size / pubfile->key_hash_cell_size <
			pubfile->number_of_key_hashes) {
		return GT_INVALID_FORMAT;
	}

	return GT_OK;
}
Ejemplo n.º 22
0
string psoCat::odbcKeyToStr( uint32_t length )
{
   psoKeyFieldDefinition * keyODBC;
   int numKeys, i;
   string outStr;
   
   keyODBC = (psoKeyFieldDefinition *) keyDef;
   numKeys = keyDefLength / sizeof(psoKeyFieldDefinition);
   
   psoaGetKeyOffsets( keyODBC, numKeys, keyOffsets );

   for ( i = 0; i < numKeys; ++i ) {
      string s;
      
      switch( keyODBC[i].type ) {

      case PSO_KEY_INTEGER:
         s = readInt32( &key[keyOffsets[i]] );
         break;

      case PSO_KEY_BIGINT:
         s = readInt64( &key[keyOffsets[i]] );
         break;

      case PSO_KEY_BINARY:
         readBinary( s,
                     keyODBC[i].length,
                     &key[keyOffsets[i]] );
         break;

      case PSO_KEY_CHAR:
         readString( s,
                     keyODBC[i].length,
                     &key[keyOffsets[i]] );
         break;

      case PSO_KEY_VARCHAR:
      case PSO_KEY_LONGVARCHAR:
         readString( s,
                     length - keyOffsets[i],
                     &key[keyOffsets[i]] );
         break;
      case PSO_KEY_VARBINARY:
      case PSO_KEY_LONGVARBINARY:
         readBinary( s,
                     length - keyOffsets[i],
                     &key[keyOffsets[i]] );
         break;

      case PSO_KEY_DATE:
         s = readDate( &key[keyOffsets[i]] );
         break;

      case PSO_KEY_TIME:
         s = readTime( &key[keyOffsets[i]] );
         break;

      case PSO_KEY_TIMESTAMP:
         s = readTimeStamp( &key[keyOffsets[i]] );
         break;
      }
      outStr += s;
      if ( i < numKeys-1) outStr += ", ";
   }
   
   return outStr;
}
Ejemplo n.º 23
0
void NmeaParser::packet_GSV(int num_params, char *params[])
{
   /*
    *
    *  GSV - Satellites in view
    *
    *  These sentences describe the sky position of a UPS satellite in view.
    *  Typically they're shipped in a group of 2 or 3.
    *
    *          1 2 3 4 5 6 7     n
    *          | | | | | | |     |
    *   $--GSV,x,x,x,x,x,x,x,...*hh<CR><LF>
    *
    *  Field Number:
    *  1) total number of messages
    *  2) message number
    *  3) satellites in view
    *  4) satellite number
    *  5) elevation in degrees (0-90)
    *  6) azimuth in degrees to true north (0-359)
    *  7) SNR in dB (0-99)
    *  more satellite infos like 4)-7)
    *  n) checksum
    *
    *  Example:
    *  $GPGSV,3,1,11,03,03,111,00,04,15,270,00,06,01,010,00,13,06,292,00*74
    *  $GPGSV,3,2,11,14,25,170,00,16,57,208,39,18,67,296,40,19,40,246,00*74
    *  $GPGSV,3,3,11,22,42,067,42,24,14,311,43,27,05,244,00,,,,*4D
    *
    */
   /* GSV can come in groups. */
   int32 numMsgs = readInt32(params[1]);
   int32 seqNum = readInt32(params[2]);
   if (seqNum == 1) {
      if (m_satInfo) {
         delete m_satInfo;
      }
      m_satInfo = new GpsSatInfoHolder();
      m_satInfoSeqId = 0;
   }
   if (m_satInfoSeqId + 1 != seqNum) {
      /* Out of order, abort. */
      return;
   } else {
      m_satInfoSeqId = seqNum;
   }
   uint32 numSat = readInt32(params[3]);

   int32 index = 4;

   while (index <= (num_params-3)) {
      int32 id    = readInt32(params[index++]);
      int32 elev  = readInt32(params[index++]);
      int32 azim  = readInt32(params[index++]);
      int32 snr   = readInt32(params[index++]);

      GpsSatInfo* info = new GpsSatInfo( id, elev, azim, snr );
      m_satInfo->addInfo(info);
   }

   if (seqNum == numMsgs) {
      /* Last message in sequence. */
      if (m_satInfo->size() != numSat) {
         DEBUG_PKT("packet_GSV - mismatch in sat num!");
      }
      if (m_consumer) {
         m_consumer->gpsSatInfo(m_satInfo);
      }

      delete m_satInfo;
      m_satInfo = 0;
      m_satInfoSeqId = 0;
   }
}
Ejemplo n.º 24
0
	void File::readInt32E(unsigned int *dest, bool big_endian) {
		if (big_endian) readInt32BE(dest);
		else readInt32(dest);
	}