示例#1
0
bool CDOMDocument::loadXML(char *xml, unsigned long len)
{
	bool ret = true;
//	void *buff;

	if(!this->parser)
		return(false);

	this->depth = -1;
	this->State = CDOMDocument::INTO_UNKNOWN;
	this->indexStart = 0;
	this->indexEnd = 0;
	this->tokenLen = 0;
	this->tokenLCLen = 0;
	this->tokenLCNDLen = 0;
	this->wordIndex = 0;
	this->parseText = true;

	if(this->path)
		_FREE(this->path);
	this->path = (char *)_MALLOC_WHY(200, "dom.cpp:loadXML:path");
	if(this->path)
	{
		this->path_msize = 200;
		this->path[0] = '\0';
		this->freepathoffset = 0;
	}

	if(this->upath)
		_FREE(this->upath);
	this->upath = (char *)_MALLOC_WHY(200, "dom.cpp:loadXML:upath");
	if(this->upath)
	{
		this->upath_msize = 200;
		this->upath[0] = '\0';
		this->freeupathoffset = 0;
	}

	if(XML_Parse(this->parser, xml, len, true) != XML_STATUS_ERROR)
	{
	}
	else
	{
		// handle parse error
		zSyslog._log(CSyslog::LOGL_ERR, CSyslog::LOGC_XMLERR, "Parse error at line %u:\n%s\n",
												  XML_GetCurrentLineNumber(this->parser),
												  XML_ErrorString(XML_GetErrorCode(this->parser)));
		ret = false;
	}

	return(ret);
}
示例#2
0
CDOMElement::CDOMElement(const char *s, class CDOMDocument *owner)
{
	int l;
	this->ownerDocument = owner;
	this->firstChild = this->lastChild = NULL;
	this->nodeType = CDOMNode::XML_ELEMENT_NODE;
	if( (this->tagName = (char *)_MALLOC_WHY(l = strlen(s)+1, "dom.h:CDOMElement:tagName")) )
		memcpy(this->tagName, s, l);

	this->valueLCND = NULL;
	this->valueLCND_buffer_size = 0;
	this->valueLCND_length = 0;

	this->valueLC = NULL;
	this->valueLC_buffer_size = 0;
	this->valueLC_length = 0;

	this->value = NULL;
	this->value_buffer_size = 0;
	this->value_length = 0;
	this->value_end = 0;

	this->index = 0;
	this->pathoffset = 0;

	this->field = NULL;

	this->index_start = this->index_end = 0;

	this->t0 = this->t1 = this->k0 = this->k1 = -1;

	this->ink = 0;

	this->lastFlags = CFLAG_ENDCHAR;
};
示例#3
0
void CIndexer::flush()
{
    if(!this->tRecord)
    {
//		printf("| nothing to flush.\n");
    }
    else
    {
        this->connbas->execute((char *)("START TRANSACTION"), 17);


        int nrecs_flushed = 0;
        // -----------------------------------------------------------------------------
        // warning : before flushing thits, we check that the thesaurus/cterms hasn't changed
        // else we will set the records as 'to-reindex-thesaurus' again
        // -----------------------------------------------------------------------------

        bool thesaurusChanged = false;

        // --------------------------------------------------- flush xpath
        CXPath *xp;
        //start by counting unknown xpath
        int nNewXPath = 0;
        for(xp = this->tXPaths; xp; xp = xp->next)
        {
            if(xp->id == 0)
                nNewXPath++;
        }
        if(nNewXPath > 0)
        {
            // there is some unknown, we get a uid and we write
            unsigned int xpath_new_uid;
            xpath_new_uid = this->connbas->getID("XPATH", nNewXPath);

            for(xp = this->tXPaths; !this->connbas->crashed && xp; xp = xp->next)
            {
                if(xp->id == 0)
                {
                    xp->new_id = xpath_new_uid++;
                    int r;
                    if((r = this->connbas->insertXPath(xp->upath, &(xp->new_id))) == 0)
                    {
                        // ok : we have created the xpath, or if it was existing the id is returned in xp->new_id
                        xp->id = xp->new_id;
                    }
                    else
                    {
                        // err : no way to create the xpath neither finding the existing one
                    }
                }
            }
        }

        // --------------------------------------------------- flush the record (delete idx, prop, thits)
        // create a list of rids
        CRecord *r;
        int lrids_len = 0;
        char *pbuff, *lrids_buff;
        for(r=this->tRecord; r; r=r->next)
            lrids_len += 34;	// 33=lmax of itoa() + comma delimiter.
        pbuff = lrids_buff = (char *)(_MALLOC_WHY(lrids_len, "indexer.cpp:flush:pbuff"));
        while( (r = this->tRecord) )
        {
            if(pbuff)
            {
                pbuff += sprintf(pbuff, "%d", r->id);
                if(r->next)
                    *pbuff++ = ',';
            }
            this->tRecord = r->next;
            delete r;

            nrecs_flushed++;
        }
        lrids_len = pbuff-lrids_buff;	// ajuste la longueur

        if(lrids_buff)
        {
            // delete idx, prop, thits for those records
            this->connbas->delRecRefs2(lrids_buff, lrids_len);

            // lock prefs and thits
//			if(!this->connbas->crashed && (this->connbas->lockPref() == 0))
//			{
            // check if something has changed in the thesaurus
            time_t struct_moddate, thesaurus_moddate, cterms_moddate;

            this->connbas->selectPref_moddates(&struct_moddate, &thesaurus_moddate, &cterms_moddate);

            thesaurusChanged = (thesaurus_moddate > this->current_thesaurus_moddate || cterms_moddate > this->current_cterms_moddate);

            if(!thesaurusChanged)
            {
                // thesaurus hasn't change
                if(!this->connbas->crashed && this->ctermsChanged)
                {
                    // cterms has changed, let's save
                    saveCterms(this);
                    this->ctermsChanged = false;
                }
            }

            // --------------------------------------------------- flush thit
            CTHit *th;
            while(!this->connbas->crashed && (th = this->firstTHit) )
            {
                if(!thesaurusChanged)
                {
                    // if the th/ct hasn't chnaged, we can flush thits
                    this->connbas->insertTHit(th->record_id, th->pxpath->id, th->pxpath->field->name, th->value, th->hitstart, th->hitlen, th->business);
                }
                this->firstTHit = th->next;
                delete th;
            }

            // we can unlock
//				this->connbas->unlockTables();

            // flag records 'to-reindex-thesaurus'
            if(!this->connbas->crashed && thesaurusChanged)
            {
                // this->connbas->execute(ibuf, pibuf-ibuf);
                // _FREE(ibuf);
                this->connbas->setRecordsToReindexTh2(lrids_buff, lrids_len);
            }
//			}

            // --------------------------------------------------- flush prop
            CProp *p;
            while(!this->connbas->crashed && (p = this->firstProp) )
            {
                this->connbas->insertProp(p->record_id, p->pxpath->id, p->pxpath->field->uname, p->value, p->type, p->business);

                this->firstProp = p->next;
                delete p;
            }


            // --------------------------------------------------- flush kword and idx
            unsigned int kword_new_uid = 0;
            if(this->nNewKeywords > 0)
                kword_new_uid = this->connbas->getID("KEYWORDS", this->nNewKeywords);

            CKword *k;
            CHit *h;

            for(int hash=0; !this->connbas->crashed && (hash<KWORD_HASHSIZE); hash++)
            {
                for(k=this->tKeywords[hash]; !this->connbas->crashed && k; k=k->next)
                {
                    // save new kwords
                    if(k->id == 0)
                    {
                        k->new_id = kword_new_uid++;
                        int r;
                        if((r = this->connbas->insertKword(k->kword, k->l, &(k->new_id))) == 0)
                        {
                            // ok : we have created the kword with new_id, or if it was existing the id is returned in k->new_id
                            k->id = k->new_id;
                        }
                        else
                        {
                        }
                    }

                    // on save les hits
                    if(k->id > 0)
                    {
                        while(!this->connbas->crashed && (h = k->firsthit) )
                        {
                            this->connbas->insertIdx(h->record_id, k->id, h->index, h->pxpath->id, h->pos, h->len, h->business);
                            k->firsthit = h->next;
                            delete h;
                        }
                    }
                }
            }
            this->nNewKeywords = 0;

            // flag the records as 'indexed' (status-bit 2,1,0 to '1')
            this->connbas->updateRecord_unlock2(lrids_buff, lrids_len);

            this->nrecsIndexed += nrecs_flushed;

            _FREE(lrids_buff);
        }

        zSyslog._log(CSyslog::LOGL_INFO, CSyslog::LOGC_INDEXING, "#%d : %d records flushed", this->connbas->sbas_id, nrecs_flushed);

        this->connbas->execute((char *)("COMMIT"), 6);

        for(xp = this->tXPaths; xp; xp = xp->next)
        {
            if(xp->id == 0 && xp->new_id != 0)
            {
                xp->id = xp->new_id;
            }
        }
        for(int hash=0; hash<KWORD_HASHSIZE; hash++)
        {
            for(CKword *k=this->tKeywords[hash]; k; k=k->next)
            {
                // save new kwords
                if(k->id == 0 && k->new_id != 0)
                {
                    k->id = k->new_id;
                }
            }
        }
    }
}