Ejemplo n.º 1
0
bool ossimXmlNode::readEndTag(std::istream& in,
                              ossimString& endTag)
{
    bool result = false;
    char c = in.peek();
    endTag = "";

    if(theTag == "--")// this is a comment tag
    {
        skipCommentTag(in);
        endTag = "--";
        return (!in.fail());
    }
    // check end tag
    //
    if(c == '/')
    {
        in.ignore();
        readTag(in, endTag);
        if(in.fail()) return false;
        xmlskipws(in);
        c = in.peek();
        result = true;
    }
    else
    {
        return false;
    }
    if(c != '>')
    {
        setErrorStatus();
        return false;
    }
    else
    {
        in.ignore(1);
    }
    if(in.fail()) result = false;

    return result;
}
Ejemplo n.º 2
0
bool ValueParser::parse() {
	_failed = false;
	_result.reserve(_end - _begin);
	for (; _ch != _end; ++_ch) {
		if (*_ch == '{') {
			appendToResult(_ch);

			++_ch;
			if (!readTag()) {
				return false;
			}

			_result.append(_currentTagReplacer);

			_begin = _ch + 1;
			_currentTag = QLatin1String("");
		}
	}
	appendToResult(_end);
	return true;
}
bool SerializedScriptValueReaderForModules::read(v8::Local<v8::Value>* value, ScriptValueCompositeCreator& creator)
{
    SerializationTag tag;
    if (!readTag(&tag))
        return false;
    switch (tag) {
    case DOMFileSystemTag:
        if (!readDOMFileSystem(value))
            return false;
        creator.pushObjectReference(*value);
        break;
    case CryptoKeyTag:
        if (!readCryptoKey(value))
            return false;
        creator.pushObjectReference(*value);
        break;
    default:
        return SerializedScriptValueReader::readWithTag(tag, value, creator);
    }
    return !value->IsEmpty();
}
Ejemplo n.º 4
0
void TagEditor::save()
{
    if(m_ui->useCheckBox->isChecked())
    {
        if(!m_tagModel->exists())
            m_tagModel->create();
         m_tagModel->setValue(Qmmp::TITLE,  m_ui->titleLineEdit->text());
         m_tagModel->setValue(Qmmp::ARTIST, m_ui->artistLineEdit->text());
         m_tagModel->setValue(Qmmp::ALBUMARTIST, m_ui->albumArtistLineEdit->text());
         m_tagModel->setValue(Qmmp::ALBUM, m_ui->albumLineEdit->text());
         m_tagModel->setValue(Qmmp::COMPOSER, m_ui->composerLineEdit->text());
         m_tagModel->setValue(Qmmp::GENRE, m_ui->genreLineEdit->text());
         m_tagModel->setValue(Qmmp::COMMENT, m_ui->commentBrowser->toPlainText ());
         m_tagModel->setValue(Qmmp::DISCNUMBER,  m_ui->discSpinBox->value());
         m_tagModel->setValue(Qmmp::YEAR, m_ui->yearSpinBox->value());
         m_tagModel->setValue(Qmmp::TRACK, m_ui->trackSpinBox->value());
    }
    else
        m_tagModel->remove();
    m_tagModel->save();
    readTag();
}
Ejemplo n.º 5
0
/*
   Parse the the file to get metadata
 */
Result SoundSourceOggVorbis::parseHeader() {
    QByteArray qBAFilename = getFilename().toLocal8Bit();
    TagLib::Ogg::Vorbis::File f(qBAFilename.constData());

    if (!readFileHeader(this, f)) {
        return ERR;
    }

    TagLib::Ogg::XiphComment *xiph = f.tag();
    if (xiph) {
        readXiphComment(this, *xiph);
    } else {
        // fallback
        const TagLib::Tag *tag(f.tag());
        if (tag) {
            readTag(this, *tag);
        } else {
            return ERR;
        }
    }

    return OK;
}
Ejemplo n.º 6
0
status WAVEFile::parseList(const Tag &id, uint32_t size)
{
	Tag typeID;
	readTag(&typeID);
	size-=4;

	if (typeID == "adtl")
	{
		/* Handle adtl sub-chunks. */
		return parseADTLSubChunk(typeID, size);
	}
	else if (typeID == "INFO")
	{
		/* Handle INFO sub-chunks. */
		return parseINFOSubChunk(typeID, size);
	}
	else
	{
		/* Skip unhandled sub-chunks. */
		fh->seek(size, File::SeekFromCurrent);
		return AF_SUCCEED;
	}
	return AF_SUCCEED;
}
Ejemplo n.º 7
0
TagCompound::TagCompound(std::stringstream &ss) :
    Tag(TAG_Compound, ss),
    _size(0),
    _width(0),
    _length(0),
    _height(0),
    _blocksData(NULL),
    _blocksId(NULL)
{
    int tagId;

    while (TAG_End != (tagId = ss.get())) {
        _data.push_back(readTag(tagId, ss));
        ++_size;

        if (NULL == _data.back()) {
            _blocksId   = NULL;
            _blocksData = NULL;
            return;
        } else if (TAG_Short == tagId) {
            if        ("Width"  == _data.back()->getName()) {
                _width  = ((TagShort*) _data.back())->getData();
            } else if ("Height" == _data.back()->getName()) {
                _height = ((TagShort*) _data.back())->getData();
            } else if ("Length" == _data.back()->getName()) {
                _length = ((TagShort*) _data.back())->getData();
            }
        } else if (TAG_Byte_Array == tagId) {
            if        ("Blocks"  == _data.back()->getName()) {
                _blocksId   = ((TagByteArray*) _data.back())->getData();
            } else if ("Data"    == _data.back()->getName()) {
                _blocksData = ((TagByteArray*) _data.back())->getData();
            }
        }
    }
}
Ejemplo n.º 8
0
void QgsOSMXmlImport::readNode( QXmlStreamReader& xml )
{
  // <node id="2197214" lat="50.0682113" lon="14.4348483" user="******" uid="595326" visible="true" version="10" changeset="10714591" timestamp="2012-02-17T19:58:49Z">
  QXmlStreamAttributes attrs = xml.attributes();
  QgsOSMId id = attrs.value( "id" ).toString().toLongLong();
  double lat = attrs.value( "lat" ).toString().toDouble();
  double lon = attrs.value( "lon" ).toString().toDouble();

  // insert to DB
  sqlite3_bind_int64( mStmtInsertNode, 1, id );
  sqlite3_bind_double( mStmtInsertNode, 2, lat );
  sqlite3_bind_double( mStmtInsertNode, 3, lon );

  if ( sqlite3_step( mStmtInsertNode ) != SQLITE_DONE )
  {
    xml.raiseError( QString( "Storing node %1 failed." ).arg( id ) );
  }

  sqlite3_reset( mStmtInsertNode );

  while ( !xml.atEnd() )
  {
    xml.readNext();

    if ( xml.isEndElement() ) // </node>
      break;

    if ( xml.isStartElement() )
    {
      if ( xml.name() == "tag" )
        readTag( false, id, xml );
      else
        xml.raiseError( "Invalid tag in <node>" );
    }
  }
}
Ejemplo n.º 9
0
void QgsOSMXmlImport::readWay( QXmlStreamReader& xml )
{
  /*
   <way id="141756602" user="******" uid="527259" visible="true" version="1" changeset="10145142" timestamp="2011-12-18T10:43:14Z">
    <nd ref="318529958"/>
    <nd ref="1551725779"/>
    <nd ref="1551725792"/>
    <nd ref="809695938"/>
    <nd ref="1551725689"/>
    <nd ref="809695935"/>
    <tag k="highway" v="service"/>
    <tag k="oneway" v="yes"/>
   </way>
  */
  QXmlStreamAttributes attrs = xml.attributes();
  QgsOSMId id = attrs.value( "id" ).toString().toLongLong();

  // insert to DB
  sqlite3_bind_int64( mStmtInsertWay, 1, id );

  if ( sqlite3_step( mStmtInsertWay ) != SQLITE_DONE )
  {
    xml.raiseError( QString( "Storing way %1 failed." ).arg( id ) );
  }

  sqlite3_reset( mStmtInsertWay );

  int way_pos = 0;

  while ( !xml.atEnd() )
  {
    xml.readNext();

    if ( xml.isEndElement() ) // </way>
      break;

    if ( xml.isStartElement() )
    {
      if ( xml.name() == "nd" )
      {
        QgsOSMId node_id = xml.attributes().value( "ref" ).toString().toLongLong();

        sqlite3_bind_int64( mStmtInsertWayNode, 1, id );
        sqlite3_bind_int64( mStmtInsertWayNode, 2, node_id );
        sqlite3_bind_int( mStmtInsertWayNode, 3, way_pos );

        if ( sqlite3_step( mStmtInsertWayNode ) != SQLITE_DONE )
        {
          xml.raiseError( QString( "Storing ways_nodes %1 - %2 failed." ).arg( id ).arg( node_id ) );
        }

        sqlite3_reset( mStmtInsertWayNode );

        way_pos++;

        xml.skipCurrentElement();
      }
      else if ( xml.name() == "tag" )
        readTag( true, id, xml );
      else
        xml.skipCurrentElement();
    }
  }
}
Ejemplo n.º 10
0
bool ossimXmlNode::read(std::istream& in)
{
    if(traceDebug())
    {
        ossimNotify(ossimNotifyLevel_DEBUG)
                << "ossimXmlNode::read: entered ......" << std::endl;
    }
    char c;
    xmlskipws(in);
    if(in.fail())
    {
        if(traceDebug())
        {
            ossimNotify(ossimNotifyLevel_DEBUG)
                    << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n";
        }
        return false;
    }
    if(in.peek() == '<')
    {
        in.ignore(1);
    }
    if(in.fail())
    {
        if(traceDebug())
        {
            ossimNotify(ossimNotifyLevel_DEBUG)
                    << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n";
        }
        return false;
    }
    streampos file_pos = in.tellg();
    ossimString endTag;

    if(!readTag(in, theTag))
    {
        if(traceDebug())
        {
            ossimNotify(ossimNotifyLevel_DEBUG)
                    << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n";
        }
        return false;
    }
    if(traceDebug())
    {
        ossimNotify(ossimNotifyLevel_DEBUG) << "theTag = " << theTag << "\n";
    }

    if((!in.fail())&&readEndTag(in, endTag))
    {
        if((endTag == "")||
                (endTag == theTag))
        {
            if(traceDebug())
            {
                ossimNotify(ossimNotifyLevel_DEBUG)
                        << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n";
            }
            return true;
        }
        else
        {
            setErrorStatus();
            if(traceDebug())
            {
                ossimNotify(ossimNotifyLevel_DEBUG)
                        << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n";
            }
            return false;
        }
    }
    // now parse attributes
    ossimRefPtr<ossimXmlAttribute> attribute = new ossimXmlAttribute;
    while(attribute->read(in))
    {
        theAttributes.push_back(new ossimXmlAttribute(*attribute));
    }
    // skip white space characters
    //
    xmlskipws(in);

    if(!in.fail()&&readEndTag(in, endTag))
    {
        if((endTag == "")||
                (endTag == theTag))
        {
            if(traceDebug())
            {
                ossimNotify(ossimNotifyLevel_DEBUG)
                        << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n";
            }
            return true;
        }
        else
        {
            setErrorStatus();
            if(traceDebug())
            {
                ossimNotify(ossimNotifyLevel_DEBUG)
                        << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n";
            }
            return false;
        }
    }
    c = in.peek();
    // make sure the attribute is closed
    //
    if(c != '>')
    {
        setErrorStatus();
        if(traceDebug())
        {
            ossimNotify(ossimNotifyLevel_DEBUG)
                    << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n";
        }
        return false;
    }

    in.ignore(1);
    c = in.peek();

    // now do the text portion
    if(!readTextContent(in))
    {
        if(traceDebug())
        {
            ossimNotify(ossimNotifyLevel_DEBUG)
                    << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n";
        }
        return false;
    }
    xmlskipws(in);
    c = in.peek();

    if(c != '<')
    {
        setErrorStatus();
        if(traceDebug())
        {
            ossimNotify(ossimNotifyLevel_DEBUG)
                    << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n";
        }
        return false;
    }
    in.ignore(1);
    if(readEndTag(in, endTag))
    {
        if((endTag == "")||
                (endTag == theTag))
        {
            if(traceDebug())
            {
                ossimNotify(ossimNotifyLevel_DEBUG)
                        << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n";
            }
            return true;
        }
        else
        {
            setErrorStatus();
            if(traceDebug())
            {
                ossimNotify(ossimNotifyLevel_DEBUG)
                        << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n";
            }
            return false;
        }
    }
    c = in.peek();

    //---
    // now if it's not an endtag then it must be a tag starting the new child
    // node
    //---
    ossimRefPtr<ossimXmlNode> childNode;
    do
    {
        childNode = new ossimXmlNode;
        childNode->setParent(this);
        if(childNode->read(in))
        {
            theChildNodes.push_back(childNode);
        }
        else
        {
            setErrorStatus();
            if(traceDebug())
            {
                ossimNotify(ossimNotifyLevel_DEBUG)
                        << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n";
            }
            return false;
        }
        xmlskipws(in);

        c = in.peek();
        if(c != '<')
        {
            setErrorStatus();
            if(traceDebug())
            {
                ossimNotify(ossimNotifyLevel_DEBUG)
                        << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n";
            }
            return false;
        }
        in.ignore(1);
        if(readEndTag(in, endTag))
        {
            if((endTag == "")||
                    (endTag == theTag))
            {
                if(traceDebug())
                {
                    ossimNotify(ossimNotifyLevel_DEBUG)
                            << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n";
                }
                return true;
            }
            else
            {
                setErrorStatus();
                if(traceDebug())
                {
                    ossimNotify(ossimNotifyLevel_DEBUG)
                            << "ossimXmlNode::read: leaving ......\n"<<__LINE__ << "\n";
                }
                return false;
            }
        }
    } while( !in.fail() );

    if(traceDebug())
    {
        ossimNotify(ossimNotifyLevel_DEBUG)
                << "ossimXmlNode::read: leaving ......\n";
    }
    return true;
}
Ejemplo n.º 11
0
status WAVEFile::readInit(AFfilesetup setup)
{
	Tag type, formtype;
	uint32_t size;
	uint32_t index = 0;

	bool hasFormat = false;
	bool hasData = false;
	bool hasCue = false;
	bool hasList = false;
	bool hasPlayList = false;
	bool hasFrameCount = false;
	bool hasINST = false;

	Track *track = allocateTrack();

	fh->seek(0, File::SeekFromBeginning);

	readTag(&type);
	readU32(&size);
	readTag(&formtype);

	assert(type == "RIFF");
	assert(formtype == "WAVE");

#ifdef DEBUG
	printf("size: %d\n", size);
#endif

	/* Include the offset of the form type. */
	index += 4;

	while (index < size)
	{
		Tag chunkid;
		uint32_t chunksize = 0;
		status result;

#ifdef DEBUG
		printf("index: %d\n", index);
#endif
		readTag(&chunkid);
		readU32(&chunksize);

#ifdef DEBUG
		printf("%s size: %d\n", chunkid.name().c_str(), chunksize);
#endif

		if (chunkid == "fmt ")
		{
			result = parseFormat(chunkid, chunksize);
			if (result == AF_FAIL)
				return AF_FAIL;

			hasFormat = true;
		}
		else if (chunkid == "data")
		{
			/* The format chunk must precede the data chunk. */
			if (!hasFormat)
			{
				_af_error(AF_BAD_HEADER, "missing format chunk in WAVE file");
				return AF_FAIL;
			}

			result = parseData(chunkid, chunksize);
			if (result == AF_FAIL)
				return AF_FAIL;

			hasData = true;
		}
		else if (chunkid == "inst")
		{
			result = parseInstrument(chunkid, chunksize);
			if (result == AF_FAIL)
				return AF_FAIL;
		}
		else if (chunkid == "fact")
		{
			hasFrameCount = true;
			result = parseFrameCount(chunkid, chunksize);
			if (result == AF_FAIL)
				return AF_FAIL;
		}
		else if (chunkid == "cue ")
		{
			hasCue = true;
			result = parseCues(chunkid, chunksize);
			if (result == AF_FAIL)
				return AF_FAIL;
		}
		else if (chunkid == "LIST" || chunkid == "list")
		{
			hasList = true;
			result = parseList(chunkid, chunksize);
			if (result == AF_FAIL)
				return AF_FAIL;
		}
		else if (chunkid == "INST")
		{
			hasINST = true;
			result = parseInstrument(chunkid, chunksize);
			if (result == AF_FAIL)
				return AF_FAIL;
		}
		else if (chunkid == "plst")
		{
			hasPlayList = true;
			result = parsePlayList(chunkid, chunksize);
			if (result == AF_FAIL)
				return AF_FAIL;
		}

		index += chunksize + 8;

		/* All chunks must be aligned on an even number of bytes */
		if ((index % 2) != 0)
			index++;

		fh->seek(index + 8, File::SeekFromBeginning);
	}

	/* The format chunk and the data chunk are required. */
	if (!hasFormat || !hasData)
	{
		return AF_FAIL;
	}

	/*
		At this point we know that the file has a format chunk
		and a data chunk, so we can assume that track->f and
		track->data_size have been initialized.
	*/
	if (!hasFrameCount)
	{
		track->totalfframes = track->data_size /
			(int) _af_format_frame_size(&track->f, false);
	}

	if (track->f.compressionType != AF_COMPRESSION_NONE &&
		(track->f.compressionType == AF_COMPRESSION_G711_ULAW ||
		track->f.compressionType == AF_COMPRESSION_G711_ALAW))
	{
		track->totalfframes = track->data_size / track->f.channelCount;
	}

	/*
		A return value of AF_SUCCEED indicates successful parsing.
	*/
	return AF_SUCCEED;
}
Ejemplo n.º 12
0
void NfcWorker::startEventLoop() {
	initialize();
	readTag(); // we're interested in reading tags right from the start
	listen();
}
Ejemplo n.º 13
0
status CAFFile::parseDescription(const Tag &, int64_t)
{
	double sampleRate;
	Tag formatID;
	uint32_t formatFlags;
	uint32_t bytesPerPacket;
	uint32_t framesPerPacket;
	uint32_t channelsPerFrame;
	uint32_t bitsPerChannel;
	if (!readDouble(&sampleRate) ||
		!readTag(&formatID) ||
		!readU32(&formatFlags) ||
		!readU32(&bytesPerPacket) ||
		!readU32(&framesPerPacket) ||
		!readU32(&channelsPerFrame) ||
		!readU32(&bitsPerChannel))
		return AF_FAIL;

	if (!channelsPerFrame)
	{
		_af_error(AF_BAD_CHANNELS, "invalid file with 0 channels");
		return AF_FAIL;
	}

	Track *track = getTrack();
	track->f.channelCount = channelsPerFrame;
	track->f.sampleWidth = bitsPerChannel;
	track->f.sampleRate = sampleRate;
	track->f.framesPerPacket = 1;

	if (formatID == "lpcm")
	{
		track->f.compressionType = AF_COMPRESSION_NONE;
		if (formatFlags & kCAFLinearPCMFormatFlagIsFloat)
		{
			if (bitsPerChannel != 32 && bitsPerChannel != 64)
			{
				_af_error(AF_BAD_WIDTH, "invalid bits per sample %d for floating-point audio data", bitsPerChannel);
				return AF_FAIL;
			}
			track->f.sampleFormat = bitsPerChannel == 32 ? AF_SAMPFMT_FLOAT :
				AF_SAMPFMT_DOUBLE;
		}
		else
		{
			track->f.sampleFormat = AF_SAMPFMT_TWOSCOMP;
		}
		track->f.byteOrder = (formatFlags & kCAFLinearPCMFormatFlagIsLittleEndian) ?
			AF_BYTEORDER_LITTLEENDIAN : AF_BYTEORDER_BIGENDIAN;

		if (_af_set_sample_format(&track->f, track->f.sampleFormat, track->f.sampleWidth) == AF_FAIL)
			return AF_FAIL;

		track->f.computeBytesPerPacketPCM();
		return AF_SUCCEED;
	}
	else if (formatID == "ulaw")
	{
		track->f.compressionType = AF_COMPRESSION_G711_ULAW;
		track->f.byteOrder = _AF_BYTEORDER_NATIVE;
		_af_set_sample_format(&track->f, AF_SAMPFMT_TWOSCOMP, 16);
		track->f.bytesPerPacket = channelsPerFrame;
		return AF_SUCCEED;
	}
	else if (formatID == "alaw")
	{
		track->f.compressionType = AF_COMPRESSION_G711_ALAW;
		track->f.byteOrder = _AF_BYTEORDER_NATIVE;
		_af_set_sample_format(&track->f, AF_SAMPFMT_TWOSCOMP, 16);
		track->f.bytesPerPacket = channelsPerFrame;
		return AF_SUCCEED;
	}
	else if (formatID == "ima4")
	{
		track->f.compressionType = AF_COMPRESSION_IMA;
		track->f.byteOrder = _AF_BYTEORDER_NATIVE;
		_af_set_sample_format(&track->f, AF_SAMPFMT_TWOSCOMP, 16);
		initIMACompressionParams();
		return AF_SUCCEED;
	}
	else
	{
		_af_error(AF_BAD_NOT_IMPLEMENTED, "Compression type %s not supported",
			formatID.name().c_str());
		return AF_FAIL;
	}
}
Ejemplo n.º 14
0
status IFFFile::readInit(AFfilesetup setup)
{
	m_fh->seek(0, File::SeekFromBeginning);

	Tag type;
	uint32_t size;
	Tag formtype;

	readTag(&type);
	readU32(&size);
	readTag(&formtype);

	if (type != "FORM" || formtype != "8SVX")
		return AF_FAIL;

	/* IFF/8SVX files have only one track. */
	Track *track = allocateTrack();
	if (!track)
		return AF_FAIL;

	/* Set the index to include the form type ('8SVX' in this case). */
	size_t index = 4;
	while (index < size)
	{
		Tag chunkid;
		uint32_t chunksize = 0;
		status result = AF_SUCCEED;

		readTag(&chunkid);
		readU32(&chunksize);

		if (chunkid == "VHDR")
		{
			result = parseVHDR(chunkid, chunksize);
		}
		else if (chunkid == "BODY")
		{
			result = parseBODY(chunkid, chunksize);
		}
		else if (chunkid == "NAME" ||
			chunkid == "AUTH" ||
			chunkid == "(c) " ||
			chunkid == "ANNO")
		{
			parseMiscellaneous(chunkid, chunksize);
		}

		if (result == AF_FAIL)
			return AF_FAIL;

		/*
			Increment the index by the size of the chunk
			plus the size of the chunk header.
		*/
		index += chunksize + 8;

		/* All chunks must be aligned on an even number of bytes. */
		if ((index % 2) != 0)
			index++;

		/* Set the seek position to the beginning of the next chunk. */
		m_fh->seek(index + 8, File::SeekFromBeginning);
	}

	/* The file has been successfully parsed. */
	return AF_SUCCEED;
}
Ejemplo n.º 15
0
static int readEccPrivateKeyOld( INOUT STREAM *stream, 
								 INOUT CONTEXT_INFO *contextInfoPtr )
	{
	CRYPT_ALGO_TYPE cryptAlgo;
	PKC_INFO *eccKey = contextInfoPtr->ctxPKC;
	long value;
	int tag, length, status;

	assert( isWritePtr( stream, sizeof( STREAM ) ) );
	assert( isWritePtr( contextInfoPtr, sizeof( CONTEXT_INFO ) ) );

	REQUIRES( contextInfoPtr->type == CONTEXT_PKC && \
			  contextInfoPtr->capabilityInfo->cryptAlgo == CRYPT_ALGO_ECDSA );

	/* Read the ECC key components.  These were never standardised in any 
	   PKCS standard, nor in the PKCS #12 RFC.  RFC 5915 "Elliptic Curve 
	   Private Key Structure" specifies the format for PKCS #8 as:

		ECPrivateKey ::= SEQUENCE {
			version			INTEGER (1),
			privateKey		OCTET STRING,
			parameters	[0]	ECParameters {{ NamedCurve }} OPTIONAL,
			publicKey	[1]	BIT STRING OPTIONAL
			}

	   but this isn't what's present in encoded forms created by OpenSSL.
	   Instead it's:

		ECSomething ::= SEQUENCE {
			version			INTEGER (0),
			parameters		SEQUENCE {
				type		OBJECT IDENTIFIER ecPublicKey,
				namedCurve	OBJECT IDENTIFIER
				}
			something		OCTET STRING {
				key			ECPrivateKey		-- As above
				}
			}

	   so we have to tunnel into this in order to find the PKCS #8-like
	   data that we're actually interested in.

	   Note that we can't use the ECC p value for a range check because it 
	   hasn't been set yet, all that we have at this point is a curve ID */
	readSequence( stream, NULL );		/* Outer wrapper */
	status = readShortInteger( stream, &value );/* Version */
	if( cryptStatusError( status ) || value != 0 )
		return( CRYPT_ERROR_BADDATA );
	status = readAlgoIDparam( stream, &cryptAlgo, &length, 
							  ALGOID_CLASS_PKC );
	if( cryptStatusError( status ) || cryptAlgo != CRYPT_ALGO_ECDSA )
		return( CRYPT_ERROR_BADDATA );
	readUniversal( stream );			/* Named curve */
	readOctetStringHole( stream, NULL, MIN_PKCSIZE_ECC_THRESHOLD, 
						 DEFAULT_TAG );		/* OCTET STRING hole wrapper */
	readSequence( stream, NULL );				/* ECPrivateKey wrapper */
	status = readShortInteger( stream, &value );	/* Version */
	if( cryptStatusError( status ) || value != 1 )
		return( CRYPT_ERROR_BADDATA );

	/* We've finalled made it down to the private key value.  At this point 
	   we can't use readBignumTag() directly because it's designed to read 
	   either standard INTEGERs (via DEFAULT_TAG) or context-specific tagged 
	   items, so passing in a BER_OCTETSTRING will be interpreted as 
	   [4] IMPLICIT INTEGER rather than an OCTET STRING-tagged integer.  To 
	   get around this we read the tag separately and tell readBignumTag() 
	   to skip the tag read */
	tag = readTag( stream );
	if( cryptStatusError( tag ) || tag != BER_OCTETSTRING )
		return( CRYPT_ERROR_BADDATA );
	return( readBignumTag( stream, &eccKey->eccParam_d,
						   ECCPARAM_MIN_D, ECCPARAM_MAX_D, NULL,
						   NO_TAG ) );
	}
Ejemplo n.º 16
0
Result SoundSourceSndFile::parseHeader()
{
    QString location = getFilename();
    setType(location.section(".",-1).toLower());

    bool is_flac = location.endsWith("flac", Qt::CaseInsensitive);
    bool is_wav = location.endsWith("wav", Qt::CaseInsensitive);
    QByteArray qBAFilename = getFilename().toLocal8Bit();

    if (is_flac) {
        TagLib::FLAC::File f(qBAFilename.constData());
        if (!readFileHeader(this, f)) {
            return ERR;
        }
        TagLib::Ogg::XiphComment* xiph = f.xiphComment();
        if (xiph) {
            readXiphComment(this, *xiph);
        }
        else {
            TagLib::ID3v2::Tag *id3v2(f.ID3v2Tag());
            if (id3v2) {
                readID3v2Tag(this, *id3v2);
            } else {
                // fallback
                const TagLib::Tag *tag(f.tag());
                if (tag) {
                    readTag(this, *tag);
                } else {
                    return ERR;
                }
            }
        }
    } else if (is_wav) {
        TagLib::RIFF::WAV::File f(qBAFilename.constData());
        if (!readFileHeader(this, f)) {
            return ERR;
        }
        TagLib::ID3v2::Tag *id3v2(f.ID3v2Tag());
        if (id3v2) {
            readID3v2Tag(this, *id3v2);
        } else {
            // fallback
            const TagLib::Tag *tag(f.tag());
            if (tag) {
                readTag(this, *tag);
            } else {
                return ERR;
            }
        }

        if (getDuration() <= 0) {
            // we're using a taglib version which doesn't know how to do wav
            // durations, set it with info from sndfile -bkgood
            // XXX remove this when ubuntu ships with an sufficiently
            // intelligent version of taglib, should happen in 11.10

            // Have to open the file for info to be valid.
            if (fh == NULL) {
                open();
            }

            if (info.samplerate > 0) {
                setDuration(info.frames / info.samplerate);
            } else {
                qDebug() << "WARNING: WAV file with invalid samplerate."
                         << "Can't get duration using libsndfile.";
            }
        }
    } else {
        // Try AIFF
        TagLib::RIFF::AIFF::File f(qBAFilename.constData());
        if (!readFileHeader(this, f)) {
            return ERR;
        }
        TagLib::ID3v2::Tag *id3v2(f.tag());
        if (id3v2) {
            readID3v2Tag(this, *id3v2);
        } else {
            return ERR;
        }
    }

    return OK;
}
Ejemplo n.º 17
0
static Patt readPatt(FILE *f) {
  int tag = readTag(f);

  switch (tag) {
  case TAG_PAPP:
    {
       CId fun = readCId(f);
       
       int i;
       int count = readInt(f);
       PattApp p = (PattApp) malloc(sizeof(struct _PattApp)+count*sizeof(Patt));
  
       p->_.tag      = tag;
       p->fun        = fun;
       p->args.count = count;
       for (i = 0; i < count; i++) {
         p->args.pats[i] = readPatt(f);
       }
       
       return ((Patt) p);
    }
  case TAG_PVAR:
    {
        PattVar p = (PattVar) malloc(sizeof(struct _PattVar));
        p->_.tag = tag;
        p->var   = readCId(f);
        return ((Patt) p);
    }
  case TAG_PAT:
    {
        PattAt p = (PattAt) malloc(sizeof(struct _PattAt));
        p->_.tag = tag;
        p->var   = readCId(f);
        p->pat   = readPatt(f);
        return ((Patt) p);
    }
  case TAG_PWILD:
    {
        PattWild p = (PattWild) malloc(sizeof(struct _PattWild));
        p->_.tag = tag;
        return ((Patt) p);
    }
  case TAG_PLIT:
    {
        PattLit p = (PattLit) malloc(sizeof(struct _PattLit));
        p->_.tag = tag;
        p->lit   = readLiteral(f);
        return ((Patt) p);
    }
  case TAG_PIMP:
    {
        PattImplArg p = (PattImplArg) malloc(sizeof(struct _PattImplArg));
        p->_.tag = tag;
        p->pat   = readPatt(f);
        return ((Patt) p);
    }
  case TAG_PTILDE:
    {
        PattTilde p = (PattTilde) malloc(sizeof(struct _PattTilde));
        p->_.tag = tag;
        p->e     = readExpr(f);
        return ((Patt) p);
    }
  default:
    __pgf_panic("Unknown pattern tag");
  }  
}
Ejemplo n.º 18
0
static void readHypo(FILE *f, Hypo h) {
  h->bt  = readTag(f);
  h->var = readCId(f);
  h->ty  = readType(f);
}
Ejemplo n.º 19
0
static Expr readExpr(FILE *f) {
  int tag = readTag(f);
  
  switch (tag) {
  case TAG_ABS:
    {
        ExprAbs e = (ExprAbs) malloc(sizeof(struct _ExprAbs));
        e->_.tag = tag;
        e->bt    = readTag(f);
        e->var   = readCId(f);
        e->body  = readExpr(f);
        return ((Expr) e);
    }
  case TAG_APP:
    {
        ExprApp e = (ExprApp) malloc(sizeof(struct _ExprApp));
        e->_.tag = tag;
        e->left  = readExpr(f);
        e->right = readExpr(f);
        return ((Expr) e);
    }
  case TAG_LIT:
    {
        ExprLit e = (ExprLit) malloc(sizeof(struct _ExprLit));
        e->_.tag = tag;
        e->lit   = readLiteral(f);
        return ((Expr) e);
    }
  case TAG_MET:
    {
        ExprMeta e = (ExprMeta) malloc(sizeof(struct _ExprMeta));
        e->_.tag = tag;
        e->id    = readInt(f);
        return ((Expr) e);
    }
  case TAG_FUN:
    {
        ExprFun e = (ExprFun) malloc(sizeof(struct _ExprFun));
        e->_.tag = tag;
        e->fun   = readCId(f);
        return ((Expr) e);
    }
  case TAG_VAR:
    {
        ExprVar e = (ExprVar) malloc(sizeof(struct _ExprVar));
        e->_.tag = tag;
        e->index = readInt(f);
        return ((Expr) e);
    }
  case TAG_TYP:
    {
        ExprTyped e = (ExprTyped) malloc(sizeof(struct _ExprTyped));
        e->_.tag = tag;
        e->e     = readExpr(f);
        e->ty    = readType(f);
        return ((Expr) e);
    }
  case TAG_IMP:
    {
        ExprImplArg e = (ExprImplArg) malloc(sizeof(struct _ExprImplArg));
        e->_.tag = tag;
        e->e     = readExpr(f);
        return ((Expr) e);
    }
  default:
    __pgf_panic("Unknown expression tag");
  }
}
Ejemplo n.º 20
0
void* PCmain(void* varg)
{
    thread_t from;
    unsigned int tag;
    char PCbuff[64];
    unsigned int msgSize = 64;
	int err;

    PCthreadArgs* targs = (PCthreadArgs*)varg;
    assert( targs != NULL );

    // define all tunable constants used by the performance Consultant
    // tunable constants must be defined here in the sequential section
    // of the code, or values specified in pcl files won't be handled 
    // properly.
    initPCconstants();

    // thread startup
    thr_name("PerformanceConsultant");
    pc = new performanceConsultant(targs->mainTid);
    msg_send (targs->mainTid, MSG_TAG_PC_READY, (char *) NULL, 0);
	from = targs->mainTid;
    tag = MSG_TAG_ALL_CHILDREN_READY;
    msg_recv (&from, &tag, PCbuff, &msgSize);
	assert( from == targs->mainTid );

    // register performance stream with data manager
    union dataCallback dataHandlers;
    struct controlCallback controlHandlers;
    memset(&controlHandlers, '\0', sizeof(controlHandlers));
    controlHandlers.fFunc = PCfold;
    controlHandlers.pFunc = PCphase;

    // At this time, don't need to to receive notice of retired resources
    //controlHandlers.retireFunc = PCresourceRetiredCallback;

    // will wait to implement this
    controlHandlers.avFunc = PCinitialActualValue;
    
    // The PC has to register a callback routine for predictedDataCost callbacks
    // even though there is a kludge in the PC to receive the msg before the
    // callback routine is called (PCpredData will never execute).  This is 
    // to maintain consistency in how the DM handles all callback functions.
    controlHandlers.cFunc = PCpredData;

    // The PC has to register a callback routine for enableDataRequest callbacks
    // even though there is a kludge in the PC to receive the msg before the
    // callback routine is called (PCenableDataCallback will never execute).  
    controlHandlers.eFunc  = PCenableDataCallback;
    // don't ask for a signal to flush our data
    controlHandlers.flFunc= 0;

    dataHandlers.sample = PCnewDataCallback;
    // the performance stream is used to identify this thread to the 
    // data manager
    performanceConsultant::pstream = dataMgr->createPerformanceStream
      (Sample, dataHandlers, controlHandlers);

    // Note: remaining initialization is application- and/or phase-specific and
    // is done after the user requests a search.

#ifdef MYPCDEBUG
    timeStamp t1 = getCurrentTime();
    timeStamp t2;
    timeLength TIME_TO_CHECK = timeLength::sec() * 2;
#endif
    while (1) {
#ifdef MYPCDEBUG
        t2 =  getCurrentTime();
        if ((t2-t1) > TIME_TO_CHECK) {
          unsigned loopLimit, loopStart;
          for (unsigned j=1;j<=1;j++) {
            if (j==1) {
              loopStart = (unsigned)T_performanceConsultant::verify + 1;
              loopLimit = (unsigned)T_performanceConsultant::last;
            }
            else {
              loopStart = (unsigned)T_dataManager::verify + 1;
              loopLimit = (unsigned)T_dataManager::last;
            }
            for (unsigned i=loopStart;i<loopLimit;i++) {
              tag = i;
              //printf("********** waiting for tag=%d\n",tag);
			  from = THR_TID_UNSPEC;
              if (msg_poll(&from, &tag, false) != THR_ERR) {
                readTag(tag);
              }
            }
          }
          t1=TESTgetTime();
        }
        else {
			from = THR_TID_UNSPEC;
			tag = MSG_TAG_THREAD;
			err = msg_poll(&from, &tag, true);
			assert(err != THR_ERR);
			readTag(tag);
        }
#else
		from = THR_TID_UNSPEC;
		tag = MSG_TAG_THREAD;
		err = msg_poll(&from, &tag, true);
		assert(err != THR_ERR);
		readTag(tag);
#endif
    }

	return NULL;
}