Exemplo n.º 1
0
Arquivo: ruleset.cpp Projeto: KDE/kppp
bool RuleSet::parseEntries(QString s, int year,
			   QTime t1, QTime t2,
			   double costs, double len, double after)
{
  // special rule: on() is the same as on(monday..sunday)
  if(s.isEmpty())
    s = "monday..sunday";

  while(s.length()) {
    int pos = s.indexOf(',');
    QString token;
    if(pos == -1) {
      token = s;
      s = "";
    } else {
      token = s.left(pos);
      s = s.right(s.length()-pos-1);
    }

    // we've a token, now check if it defines a
    // range
    RULE r;
    if(token.contains("..")) {
      QString left, right;
      left = token.left(token.indexOf(".."));
      right = token.right(token.length()-2-left.length());
      RULE lr, rr;
      if(parseEntry(lr, left, year) && parseEntry(rr, right, year)) {
	if(lr.type == rr.type) {
	  r.type = lr.type;
	  switch(lr.type) {
	  case 1:
	    r.date.from = lr.date.from;
	    r.date.until = rr.date.from;
	    break;
	  case 2:
	    r.weekday.from = lr.weekday.from;
	    r.weekday.until = rr.weekday.from;
	  }
	} else
	  return false;
      }
    } else
      if(!parseEntry(r, token, year))
	return false;

    r.costs = costs;
    r.len = len;
    r.after = after;
    r.from = t1;
    r.until = t2;
    addRule(r);
  }

  return true;
}
Exemplo n.º 2
0
void		Network::receiveFromServer()
{
  char		buf[BUFF_SIZE];
  std::string	entry;

  _safeEvents->setDrawing(true);
  while (_safeEvents->getDrawing())
    {
      FD_ZERO(&_rfds);
      FD_SET(_socket, &_rfds);
      if (select(_socket + 1, &_rfds, NULL, NULL, &_timeOut) == FAIL)
  	throw ZappyError::SystemError(errno, "Error : Select");
      if (FD_ISSET(_socket, &_rfds))
  	{
  	  bzero(buf, BUFF_SIZE);
	  while (strchr(buf, 10) == NULL)
	    if (recv(_socket, buf, BUFF_SIZE - 1, 0) <= 0)
	      throw ZappyError::SystemError(errno, "Error : Connection Lost");
	  entry = _remain + buf;
	  _remain.clear();
	  parseEntry(entry);
	  _commands.parseAllCommands(entry);
	}
      checkTime();
    }
}
Exemplo n.º 3
0
bool prepare_query(const char* entry) {
  position = 0;
  auto parsed_entry = parseEntry(entry);
  std::vector<std::vector<bool>> queryset;
  queryset.push_back(parsed_entry);
  if (querypoint != nullptr)
      delete[] querypoint;
  if (numres != nullptr) {
      delete numres[0];
      delete[] numres;
  }
  if (results != nullptr) {
      delete[] results[0];
      delete[] results;
  }
  results = new UINT32*[1];
  numres = new UINT32*[1];
  numres[0] = new UINT32[B + 1];
  querypoint = create_dataset(queryset);
  if (r > 0) {
      UINT8* new_query = new UINT8[B/8];
      reorder(new_query, querypoint, 1, B, order);
      delete[] querypoint;
      querypoint = new_query;
  }
  return true;
}
QTreeWidget* ReadAndWriteXML::parseXMLToQTreeWidget(const QDomDocument *doc, QTreeWidget * treeWidget) {
    //VERIFYING IS A NODE
    if (doc==NULL) {
        QMessageBox::warning(0, "parseXMLToQTreeWidget","NULL POINTER");
        Q_ASSERT(FALSE);
    }
    if (doc->isNull()){
        QMessageBox::warning(0, "parseXMLToQTreeWidget","QDomDocument is null");
        Q_ASSERT(FALSE);
    }
    if (!doc->isDocument()) {
       QMessageBox::warning(0, "parseXMLToQTreeWidget",QObject::tr("QDomDocument is not a document is %1 ").arg(doc->nodeType()));
       Q_ASSERT(FALSE);
    }

    if (treeWidget==NULL) treeWidget=new QTreeWidget();
    else treeWidget->clear();
    qDebug() << "DomParser::parseXMLToQTreeWidget  start parsing " << doc->nodeName() ;

    QDomNode node = doc->firstChild();
    qDebug() << "DomParser::parseXMLToQTreeWidget  first child is " << node.nodeName() ;
    QTreeWidgetItem *item = new QTreeWidgetItem(treeWidget,QStringList(QString("Type: %1").arg(node.nodeName())));
    treeWidget->addTopLevelItem(item);
    treeWidget->setColumnCount(1);

    while (!node.isNull()) {
        parseEntry(node.toElement(), item);
        node = node.nextSibling();
    }
    return treeWidget;
}
Exemplo n.º 5
0
// static
int BibTeXFile::readEntry(Entry & e, const QByteArray & content, int curPos, const QTextCodec * codec)
{
	QList<QString> delims;
	curPos = content.indexOf('@', curPos);
	if (curPos < 0)
		return -1;
	++curPos;
	int start = content.indexOf('{', curPos);
	if (start < 0)
		return -1;
	e._type = codec->toUnicode(content.mid(curPos, start - curPos));

	int end = findBlock(content, start);
	if (end < 0) return -1;
	++start;
	QByteArray block = content.mid(start, end - start);

	switch (e.type()) {
	case Entry::COMMENT:
		e._key = codec->toUnicode(block);
		break;
	case Entry::PREAMBLE:
		e._key = codec->toUnicode(block);
		break;
	case Entry::STRING:
		// FIXME
		e._key = codec->toUnicode(block);
		break;
	case Entry::NORMAL:
		parseEntry(e, codec->toUnicode(block));
		break;
	}

	return end + 1;
}
Exemplo n.º 6
0
bool RewriteMapParser::parse(std::unique_ptr<MemoryBuffer> &MapFile,
                             RewriteDescriptorList *DL) {
  SourceMgr SM;
  yaml::Stream YS(MapFile->getBuffer(), SM);

  for (auto &Document : YS) {
    yaml::MappingNode *DescriptorList;

    // ignore empty documents
    if (isa<yaml::NullNode>(Document.getRoot()))
      continue;

    DescriptorList = dyn_cast<yaml::MappingNode>(Document.getRoot());
    if (!DescriptorList) {
      YS.printError(Document.getRoot(), "DescriptorList node must be a map");
      return false;
    }

    for (auto &Descriptor : *DescriptorList)
      if (!parseEntry(YS, Descriptor, DL))
        return false;
  }

  return true;
}
Exemplo n.º 7
0
void AbrStructParser::parse(QString fileName){
    QFile file(fileName);
    if (!file.open(QIODevice::ReadOnly))
    {
        qDebug() << "Can't open file " << fileName;
        return;
    }
    QDataStream buf(&file); 

    
    // offset in bytes
    short int vermaj, vermin; 
    buf >> vermaj;
    buf >> vermin;
    qDebug() << "Version: " << vermaj << "." << vermin;
    
    int index = file.readAll().indexOf("8BIMdesc");
    buf.device()->seek(index);
    int status = 0;
    while (!buf.atEnd()){
        status = parseEntry(buf);
        if (status == -1){
            // something to break the parsing with fail?
            qDebug() << "Finishing with fail...";
            break;
        }
    }
    qDebug() << m_doc.toString();
}
Exemplo n.º 8
0
void Parser::setEntryAndParse(class Entry *entry_)
{
    entry = entry_;

    /* Now allocate the new one */

    parseEntry();
}
bool prepare_query(const char* entry) {
  position = 0;
  results_idxs.clear();
  if (parsed_entry == nullptr)
    delete[] parsed_entry;
  parsed_entry = mapEntry(parseEntry(entry));
  return true;
}
Exemplo n.º 10
0
void ReadAndWriteXML::parseAttribute(const QDomNamedNodeMap &element, QTreeWidgetItem *parent, int parentLevel) {
    for (unsigned int n=0;n<element.length(); n++) {
        QDomNode node=element.item(n);
        Q_ASSERT(node.isAttr());
        QTreeWidgetItem *childitem=new QTreeWidgetItem(parent, QStringList(QString("Attribute: %1=%2").arg(node.nodeName()).arg(node.toAttr().nodeValue())));
        parseEntry(node.toElement(), childitem,++parentLevel);
    }
}
Exemplo n.º 11
0
void K3bCddbLocalQuery::doQuery()
{
  emit infoMessage( i18n("Searching entry in %1").arg( m_cddbDir ) );
  kapp->processEvents(); //BAD!

  QString path = preparePath( m_cddbDir );

  kdDebug() << "(K3bCddbLocalQuery) searching in dir " << path << " for " 
	    << QString::number( toc().discId(), 16 ).rightJustify( 8, '0' ) << endl;

  for( QStringList::const_iterator it = categories().begin();
       it != categories().end(); ++it ) {

    QString file = path + *it + "/" +  QString::number( toc().discId(), 16 ).rightJustify( 8, '0' );

    if( QFile::exists( file ) ) {
      // found file
      
      QFile f( file );
      if( !f.open( IO_ReadOnly ) ) {
	kdDebug() << "(K3bCddbLocalQuery) Could not open file" << endl;
      }
      else {
	QTextStream t( &f );

	K3bCddbResultEntry entry;
	parseEntry( t, entry );
	K3bCddbResultHeader header;
	header.discid = QString::number( toc().discId(), 16 ).rightJustify( 8, '0' );
	header.category = *it;
	header.title = entry.cdTitle;
	header.artist = entry.cdArtist;
	m_inexactMatches.append(header);
      }
    }
    else {
      kdDebug() << "(K3bCddbLocalQuery) Could not find local entry in category " << *it << endl;
    }
  }

  if( m_inexactMatches.count() > 0 ) {
    setError( SUCCESS );
    if( m_inexactMatches.count() == 1 ) {
      queryMatch( m_inexactMatches.first() );
    }
    else {
      emit inexactMatches( this );
    }
  }
  else {
    setError( NO_ENTRY_FOUND );
    emit queryFinished( this );
  }
}
Exemplo n.º 12
0
	RESULT YaDiskRVFSDriver::getElements(QList<VFSElement>& elements)
	{
		RESULT err = eERROR_GENERAL;
		for(int i=0; i<elements.count()&&elements[i].getType()==VFSElement::DIRECTORY; i++)
		{
			QString xmlResp = "";
			QString path = elements[i].getSrcUrl();
            err = m_httpConnector->getTreeElements(path, xmlResp);
			if(err || xmlResp.length() == 0)
			{
				continue;
			}

			QDomDocument xml;
			xml.setContent(xmlResp);
			QDomElement  root         = xml.firstChildElement(); // <multistatus> root element
			QDomNode  responseElement = root.firstChildElement(); // <response>

			while(!responseElement.isNull())
			{
				VFSElement elem;

				parseEntry(responseElement, elem);
				if(elem.getSrcUrl() != elements[i].getSrcUrl()) // skip duplicates
				{
					elem.setParentId(elements[i].getId());
					QString path = elements[i].getPath() + QString(QDir::separator()) + elem.getName();
					QFileInfo fInfo(path);
					elem.setPath(fInfo.absoluteFilePath());

					elem.setDownloaded(false);
					elements.append(elem);
				}

				responseElement = responseElement.nextSibling(); //next element
			}
		}

		if(err == eNO_ERROR)
		{
			//Populate path for elemenets
			for(int k=0, count = elements.count(); k < count; k++)
			{
				elements[k].setPath(QFileInfo(getElementPath(elements, elements[k])).absoluteFilePath());
			}

			handleNameDuplicates(elements);
		}

		return err;
	}
Exemplo n.º 13
0
QStringList RSS::parse(QDomDocument document) {
    qDebug("[RSS] parses DomDocument");
    QStringList list;
    QDomElement root = document.documentElement();
    if (root.tagName() != "rss") {
        qDebug("Incompatible tagName: %s", qPrintable(root.tagName()));
        return list;
    }
    QDomElement entry = root.firstChildElement("channel");
    entry = entry.firstChildElement("item");
    while (!entry.isNull()) {
        list.append(parseEntry(entry));
        entry = entry.nextSiblingElement();
    }
    return list;
}
Exemplo n.º 14
0
void K3bCddbLocalQuery::doMatchQuery()
{
  QString path = preparePath( m_cddbDir ) + header().category + "/" + header().discid;

  QFile f( path );
  if( !f.open( IO_ReadOnly ) ) {
    kdDebug() << "(K3bCddbLocalQuery) Could not open file" << endl;
    setError( READ_ERROR );
  }
  else {
    QTextStream t( &f );
    
    parseEntry( t, result() );
    result().discid = header().discid;
    result().category = header().category;
    setError( SUCCESS );
  }
  emit queryFinished( this );
}
Exemplo n.º 15
0
void KeePassXmlStreamReader::parseGroup(){
    while(xmlReader.readNextStartElement()){
        if(xmlReader.name() == "title"){
            if(! groupTitle.isEmpty()) groupTitleStack.append(groupTitle);
            groupTitle = xmlReader.readElementText();
        }else if(xmlReader.name() == "entry"){
            qDebug("Found entry in group.");
            parseEntry();
        }else if(xmlReader.name() == "group"){
            qDebug("Found group in group.");
            parseGroup();
        }else{
            qDebug("Skipping group child element: %s", xmlReader.name().toString().toUtf8().constData());
            xmlReader.skipCurrentElement();
        }
    }
    resetMembers();
    qDebug("Leaving parseGroup...");
}
Exemplo n.º 16
0
BibLaTeXItemCollection BibFile::getDocuments() const
{
	BibLaTeXItemCollection documents;

	QFile bibFile(m_filePath);

	if (!bibFile.open(QIODevice::ReadOnly))
		return documents;

	QTextStream in(&bibFile);

	QString content = in.readAll();

	for (QString bibEntry : findEntries(content))
	{
		// TODO: These need to be processed at least string
		if (bibEntry == "preamble" || bibEntry == "string" || bibEntry == "comment" )
			continue;
		documents.append(parseEntry(bibEntry));
	}
	return documents;
}
Exemplo n.º 17
0
IntelMP::Result IntelMP::discover()
{
    MPConfig *mpc = 0;
    MPEntry *entry;
    MPFloat *mpf;
    Address addr = m_io.getBase();

    // Clear previous discoveries
    m_cpus.clear();

    // Look for the Multiprocessor configuration
    for (uint i = 0; i < MPAreaSize; i += sizeof(Address))
    {
        mpf = (MPFloat *)(addr + i);

        if (mpf->signature == MPFloatSignature)
        {
            mpc = (MPConfig *) mpf->configAddr;
            break;
        }
    }
    // MPTables not found
    if (!mpc)
        return NotFound;

    // Found config
    NOTICE("MP header found at " << mpc);
    NOTICE("Local APIC at " << (void *) mpc->apicAddr);
    entry = (MPEntry *)(mpc + 1);

    // Search for multiprocessor entries
    for (uint i = 0; i < mpc->count; i++)
        entry = parseEntry(entry);

    // Remap APIC in virtual memory
    m_apic.getIO().map(mpc->apicAddr, PAGESIZE);

    return Success;
}
Exemplo n.º 18
0
int main() {

    char *line = NULL;
    size_t size;
    
    initSegIndex();
    initSegCounter();

    while(getline(&line, &size, stdin) != -1) {
   
        char *key = NULL;
        char *val = NULL;
        parseEntry(line, size, &key, &val);   
        if(key==NULL) continue;
        decodeKey(key);
        decodeVal(val);   
        
        // hash_set(index, key, val);
    }
    // readline - mallocs space
    free(line);

    // fprintf(stderr, "Hash values: %d\n", hash_size(index));
    // hash_each(index, {
    //   printf("%s: %s\n", key, (char *) val);

    //   // release key/val - parseEntry strdup key/val on heap
    //   free((char *)key);
    //   free((char *)val);
    // });
    // hash_free(index);
    
    printSegCounter();

    clearSegCounter();
    clearSegIndex();

    return 0;
}
Exemplo n.º 19
0
void ReadAndWriteXML::parseEntry(const QDomElement &element, QTreeWidgetItem *parent, int parentLevel)
{
 //   item->setText(0, element.attribute("term"));
    QDomNode node = element.firstChild();
    while (!node.isNull()) {
        //qDebug() << "DomParser::parseEntry  node " << node.toElement().tagName();
    //    qDebug() << "DomParser::parseEntry  parsing node " << node.nodeName();
         if (node.isElement()) {
            //qDebug() << "DomParser::parseEntry "<< node.nodeName()<< " is element ";
            QTreeWidgetItem *childitem=new QTreeWidgetItem(parent, QStringList(QString("Type: %1").arg(node.nodeName())));
            parseEntry(node.toElement(), childitem,++parentLevel);
            QString _attr="";
            if (node.hasAttributes()) {
               childitem=new QTreeWidgetItem(childitem, QStringList(QString("Attributes node %1").arg(node.nodeName())));
               parseAttribute(node.attributes(), childitem, parentLevel);
            }
            node = node.nextSibling();
            continue;
         }
         if (node.isCDATASection()) {
             //qDebug() << "DomParser::parseEntry "<< node.nodeName()<< " is CDATASection --" << node.toText().data() << "--";
             new QTreeWidgetItem(parent, QStringList(QString("Type: %1 Value: %2").arg(node.nodeName(),node.toText().data())));
             node = node.nextSibling();
             continue;
         }
         if (node.isComment()) {
            //qDebug() << "DomParser::parseEntry "<< node.nodeName()<< " is comment --" << node.toText().data() << "--";
            new QTreeWidgetItem(parent, QStringList(QString("Type: %1 Value: %2").arg(node.nodeName(),node.toText().data())));
            node = node.nextSibling();
            continue;
         }
         if (node.isText()) {
            //qDebug() << "DomParser::parseEntry "<< node.nodeName()<< " text --" << node.toText().data() << "--";
            new QTreeWidgetItem(parent, QStringList(QString("Type: %1 Value: %2").arg(node.nodeName(),node.toText().data())));
            node = node.nextSibling();
            continue;
         }
         if (node.isDocument()) {
            //qDebug() << "DomParser::parseEntry "<< node.nodeName()<< " is document ";
            QTreeWidgetItem *childitem=new QTreeWidgetItem(parent, QStringList(QString("Type: %1").arg(node.nodeName())));
            parseEntry(node.toElement(), childitem,++parentLevel);
            node = node.nextSibling();
            continue;
         }
         if (node.isDocumentType()) {
            qDebug() << "DomParser::parseEntry "<< node.nodeName()<< " is  document type";
            QTreeWidgetItem *childitem=new QTreeWidgetItem(parent, QStringList(QString("Type: %1").arg(node.nodeName())));
            parseEntry(node.toElement(), childitem,++parentLevel);
            node = node.nextSibling();
            continue;
         }
         if (node.isDocumentFragment()) {
            qDebug() << "DomParser::parseEntry "<< node.nodeName()<< " is  document fragment";
            QTreeWidgetItem *childitem=new QTreeWidgetItem(parent, QStringList(QString("Type: %1").arg(node.nodeName())));
            parseEntry(node.toElement(), childitem,++parentLevel);
            node = node.nextSibling();
            continue;
         }
         if (node.isEntity() || node.isEntityReference () || node.isNotation () || node.isProcessingInstruction ()) {
             qDebug() << "DomParser::parseEntry "<< node.nodeName()<< " is  not supported";
             node = node.nextSibling();
             continue;
         }

        node = node.nextSibling();
    }
}
Exemplo n.º 20
0
void QtgdataClient::onAtomFeedRetrieved(QByteArray reply)
{
#ifdef QTGDATA_DEBUG
    qDebug() << "onAtomFeedRetrieved. Client ID: " << ID;
#endif
    XMLParser parser;
    try {
        IEntity *entity = parser.parse(reply,reply.size());
        if((entity != NULL)&&(entity->getId() != Id::NULLID))
        {
            if(entity->getId() == Id::feed)
            {                
                atomFeed = createAtomFeed();
                IEntity::itConstEntities begin,end;
                entity->getEntityList(begin,end);                
                if(begin != end)
                {
                    for(IEntity::itConstEntities it = begin; it != end; it++ )
                    {
                        IEntity *sit = dynamic_cast<IEntity *>(*it);
                        switch(sit->getId())
                        {
                        case Id::id:
                            atomFeed->id = sit->getValue();
                            break;
                        case Id::updated:
                            atomFeed->updated.fromString(sit->getValue(),Qt::ISODate);
                            break;
                        case Id::title:
                            atomFeed->title = sit->getValue();
                            break;
                        case Id::generator:
                            atomFeed->generator.generator = sit->getValue();
                            atomFeed->generator.version = sit->getAttribute(AttributeId::version)->sValue;
                            atomFeed->generator.uri = QUrl(sit->getAttribute(AttributeId::uri)->sValue);
                            break;
                        case Id::author:
                        {
                            IEntity *aux = NULL;
                            Author author;
                            if((aux=sit->getEntity(Id::name)))
                                author.name = aux->getValue();
                            aux = NULL;
                            if(aux=sit->getEntity(Id::uri))
                                author.uri = QUrl(aux->getValue());
                            aux = NULL;
                            if(aux=sit->getEntity(Id::email))
                                author.email = aux->getValue();
                            atomFeed->authors.append(author);
                            break;
                        }
                        case Id::link:
                        {
                            Link link;
                            link.href = QUrl(sit->getAttribute(AttributeId::href)->sValue);
                            link.rel = sit->getAttribute(AttributeId::rel)->sValue;
                            link.type = sit->getAttribute(AttributeId::type)->sValue;
                            atomFeed->links.append(link);
                            break;
                        }
                        case Id::entry:
                        {
                            AtomEntry *atomEntry = createAtomEntry();
                            IEntity::itConstEntities entryBegin,entryEnd;
                            sit->getEntityList(entryBegin,entryEnd);
                            for(IEntity::itConstEntities itEntry = entryBegin;
                                itEntry != entryEnd;
                                itEntry++)
                            {
                                IEntity *entry = dynamic_cast<IEntity *>(*itEntry);
                                int id = entry->getId();
                                switch(id)
                                {
                                case Id::author: {
                                    IEntity *author = entry->getEntity(Id::author);
                                    if((author)&&(author->getId()))
                                    {
                                        IEntity *aux = NULL;
                                        if((aux=author->getEntity(Id::name)))
                                        {
                                            Author author;
                                            author.name = aux->getValue();
                                            atomEntry->authors.append(author);
                                        }
                                    }
                                    break;
                                }
                                case Id::id:
                                    atomEntry->id = entry->getValue();
                                    break;
                                case Id::published:
                                    atomEntry->published.fromString(entry->getValue(),Qt::ISODate);
                                    break;
                                case Id::updated:
                                    atomEntry->updated.fromString(entry->getValue(),Qt::ISODate);
                                    break;
                                case Id::summary:
                                    atomEntry->summary = entry->getValue();
                                    break;
                                case Id::title:
                                    atomEntry->title = entry->getValue();
                                    break;
                                case Id::link:
                                {
                                    Link link;
                                    link.href = QUrl(entry->getAttribute(AttributeId::href)->sValue);
                                    link.rel = entry->getAttribute(AttributeId::rel)->sValue;
                                    link.type = entry->getAttribute(AttributeId::type)->sValue;
                                    atomEntry->links.append(link);
                                    break;
                                }
                                case Id::content:
                                {
                                    atomEntry->content.type = entry->getAttribute(AttributeId::type)->sValue;
                                    atomEntry->content.content = QByteArray(entry->getValue().toAscii());;
                                    break;
                                }
                                default:
                                    parseEntry(id,atomEntry,entry);
                                    break;
                                }
                            }
                            appendEntry(atomEntry);
                        }
                        }
                     }
                }                
                emitAtomFeedRetrieved();
            } // if feed
        }
        delete entity;
    } catch(XMLParserException e) {
        qDebug() << e.what();
    }
}
Exemplo n.º 21
0
/* reads a PIE feed URL and returns a new channel structure (even if
   the feed could not be read) */
static void pie_parse(feedParserCtxtPtr ctxt, xmlNodePtr cur) {
	gchar			*tmp2, *tmp = NULL, *tmp3;
	NsHandler		*nsh;
	parseChannelTagFunc	pf;
	
	while(TRUE) {
		if(xmlStrcmp(cur->name, BAD_CAST"feed")) {
			g_string_append(ctxt->feed->parseErrors, "<p>Could not find Atom/Echo/PIE header!</p>");
			break;			
		}

		/* parse feed contents */
		cur = cur->xmlChildrenNode;
		while(cur) {
			if(!cur->name || cur->type != XML_ELEMENT_NODE) {
				cur = cur->next;
				continue;
			}
			
			/* check namespace of this tag */
			if(cur->ns) {
				if((cur->ns->href && (nsh = (NsHandler *)g_hash_table_lookup(ns_pie_ns_uri_table, (gpointer)cur->ns->href))) ||
				   (cur->ns->prefix && (nsh = (NsHandler *)g_hash_table_lookup(pie_nstable, (gpointer)cur->ns->prefix)))) {
					pf = nsh->parseChannelTag;
					if(pf)
						(*pf)(ctxt, cur);
					cur = cur->next;
					continue;
				} else {
					/*g_print("unsupported namespace \"%s\"\n", cur->ns->prefix);*/
				}
			} /* explicitly no following else !!! */
			
			if(!xmlStrcmp(cur->name, BAD_CAST"title")) {
				tmp = unhtmlize(pie_parse_content_construct(cur));
				if(tmp) {
					if(ctxt->title)
						g_free(ctxt->title);
					ctxt->title = tmp;
				}
			} else if(!xmlStrcmp(cur->name, BAD_CAST"link")) {
				tmp = xml_get_attribute (cur, "href");
				if(tmp) {				
					/* 0.3 link : rel, type and href attribute */
					tmp2 = xml_get_attribute (cur, "rel");
					if(tmp2 && g_str_equal(tmp2, "alternate"))
						subscription_set_homepage (ctxt->subscription, tmp);
					/* else
						FIXME: Maybe do something with other links? */
					g_free(tmp2);
					g_free(tmp);
				} else {
					/* 0.2 link : element content is the link, or non-alternate link in 0.3 */
					tmp = (gchar *)xmlNodeListGetString(ctxt->doc, cur->xmlChildrenNode, 1);
					if(tmp) {
						subscription_set_homepage (ctxt->subscription, tmp);
						g_free(tmp);
					}
				}
				
			/* parse feed author */
			} else if(!xmlStrcmp(cur->name, BAD_CAST"author")) {
				/* parse feed author */
				tmp = parseAuthor(cur);
				if(tmp) {
					ctxt->subscription->metadata = metadata_list_append(ctxt->subscription->metadata, "author", tmp);
					g_free(tmp);
				}
			} else if (!xmlStrcmp (cur->name, BAD_CAST"tagline")) {
				tmp = pie_parse_content_construct (cur);
				if (tmp) {
					metadata_list_set (&ctxt->subscription->metadata, "description", tmp);
					g_free (tmp);				
				}
			} else if(!xmlStrcmp(cur->name, BAD_CAST"generator")) {
				tmp = unhtmlize((gchar *)xmlNodeListGetString(ctxt->doc, cur->xmlChildrenNode, 1));
				if(tmp && tmp[0] != '\0') {
					tmp2 = xml_get_attribute (cur, "version");
					if(tmp2) {
						tmp3 = g_strdup_printf("%s %s", tmp, tmp2);
						g_free(tmp);
						g_free(tmp2);
						tmp = tmp3;
					}
					tmp2 = xml_get_attribute (cur, "url");
					if(tmp2) {
						tmp3 = g_strdup_printf("<a href=\"%s\">%s</a>", tmp2, tmp);
						g_free(tmp2);
						g_free(tmp);
						tmp = tmp3;
					}
					ctxt->subscription->metadata = metadata_list_append(ctxt->subscription->metadata, "feedgenerator", tmp);
				}
				g_free(tmp);
			} else if(!xmlStrcmp(cur->name, BAD_CAST"copyright")) {
				tmp = pie_parse_content_construct(cur);
				if(tmp) {
					ctxt->subscription->metadata = metadata_list_append(ctxt->subscription->metadata, "copyright", tmp);
					g_free(tmp);
				}				
				
			} else if(!xmlStrcmp(cur->name, BAD_CAST"modified")) { /* Modified was last used in IETF draft 02) */
				tmp = (gchar *)xmlNodeListGetString(ctxt->doc, cur->xmlChildrenNode, 1);
				if(tmp) {
					ctxt->subscription->metadata = metadata_list_append(ctxt->subscription->metadata, "pubDate", tmp);
					ctxt->feed->time = date_parse_ISO8601 (tmp);
					g_free(tmp);
				}

			} else if(!xmlStrcmp(cur->name, BAD_CAST"updated")) { /* Updated was added in IETF draft 03 */
				tmp = (gchar *)xmlNodeListGetString(ctxt->doc, cur->xmlChildrenNode, 1);
				if(tmp) {
					ctxt->subscription->metadata = metadata_list_append(ctxt->subscription->metadata, "pubDate", tmp);
					ctxt->feed->time = date_parse_ISO8601 (tmp);
					g_free(tmp);
				}

			} else if(!xmlStrcmp(cur->name, BAD_CAST"contributor")) { 
				tmp = parseAuthor(cur);
				if(tmp) {
					ctxt->subscription->metadata = metadata_list_append(ctxt->subscription->metadata, "contributor", tmp);
					g_free(tmp);
				}
				
			} else if((!xmlStrcmp(cur->name, BAD_CAST"entry"))) {
				ctxt->item = parseEntry(ctxt, cur);
				if(ctxt->item) {
					if(0 == ctxt->item->time)
						ctxt->item->time = ctxt->feed->time;
					ctxt->items = g_list_append(ctxt->items, ctxt->item);
				}
			}
			
			cur = cur->next;
		}
		
		break;
	}
}
Exemplo n.º 22
0
bool train(const char* entry) {
  auto parsed_entry = parseEntry(entry);
  pointset.push_back(parsed_entry);
  entry_count++;
  return true;
}