コード例 #1
0
ファイル: minixml.c プロジェクト: Charlschun/Colloquy
/* parseelt parse the xml stream and
 * call the callback functions when needed... */
static void parseelt(struct xmlparser * p)
{
	int i;
	const char * elementname;
	while(p->xml < (p->xmlend - 1))
	{
		if((p->xml)[0]=='<' && (p->xml)[1]!='?')
		{
			i = 0; elementname = ++p->xml;
			while( !IS_WHITE_SPACE(*p->xml)
				  && (*p->xml!='>') && (*p->xml!='/')
				 )
			{
				i++; p->xml++;
				if (p->xml >= p->xmlend)
					return;
				/* to ignore namespace : */
				if(*p->xml==':')
				{
					i = 0;
					elementname = ++p->xml;
				}
			}
			if(i>0)
			{
				if(p->starteltfunc)
					p->starteltfunc(p->data, elementname, i);
				if(parseatt(p))
					return;
				if(*p->xml!='/')
				{
					const char * data;
					i = 0; data = ++p->xml;
					if (p->xml >= p->xmlend)
						return;
					while( IS_WHITE_SPACE(*p->xml) )
					{
						p->xml++;
						if (p->xml >= p->xmlend)
							return;
					}
					while(*p->xml!='<')
					{
						i++; p->xml++;
						if (p->xml >= p->xmlend)
							return;
					}
					if(i>0 && p->datafunc)
						p->datafunc(p->data, data, i);
				}
			}
			else if(*p->xml == '/')
			{
				i = 0; elementname = ++p->xml;
				if (p->xml >= p->xmlend)
					return;
				while((*p->xml != '>'))
				{
					i++; p->xml++;
					if (p->xml >= p->xmlend)
						return;
				}
				if(p->endeltfunc)
					p->endeltfunc(p->data, elementname, i);
				p->xml++;
			}
		}
		else
		{
			p->xml++;
		}
	}
}
コード例 #2
0
ファイル: MD2.CPP プロジェクト: johnBradley501/TACT
/* MDEXTID: Process external identifier parameter of a markup declaration.
            On entry, tbuf contains SYSTEM or PUBLIC if all is well.
            NULL is returned if an error, otherwise fpis.  If it is a
            valid external data entity, the caller's estore is set to ESN
            and its nxetype is set to the code for the external entity type.
            The event that terminated the parse is preserved in pcb.action,
            so the caller should process it before further parsing.
*/
struct fpi *mdextid(UNCH *tbuf,        /* Work area for tokenization[2*(LITLEN+2)]. */
						  struct fpi *fpis,  /* FPI structure. */
						  UNCH *ename,       /* Entity or notation name, with EOS, no length.*/
													/* NOTE: No PERO on parameter entity name. */
						  UNCH *estore,      /* DTD, general or parameter entity, DCN. */
						  PNE pne)           /* Caller's external entity ptr. */
{
     PDCB dcb;                /* Ptr to DCN control block. */
     int exidtype;            /* External ID type: 0=none 1=system 2=public. */
     int exetype;             /* External entity type. */

     MEMZERO((UNIV)fpis, (UNS)FPISZ);     /* Initialize fpi structure. */
     /* Move entity name into fpi (any PERO was stripped by caller). */
     fpis->fpinm = ename;
     entlen = 0;              /* Initialize external ID length. */

     /* PARAMETER 1: External identifier keyword or error.
     */
     TRACEMD("1: extid keyword");
     if ((exidtype = mapsrch(exttab, tbuf+1))==0) {
          mderr(29, (UNCH *)0, (UNCH *)0);
          return (struct fpi *)0;
     }
     if (exidtype==EDSYSTEM) goto parm3;

     /* PARAMETER 2: Public ID literal.
     */
     pcbmd.newstate = 0;
     /* The length of a minimum literal cannot exceed the value of LITLEN
	in the reference quantity set. */
     parsemd(pubibuf, NAMECASE, &pcblitv, REFLITLEN);
     TRACEMD("2: pub ID literal");
     switch (pcbmd.action) {
     case LITE:               /* Use alternative literal delimiter. */
     case LIT:                /* Save literal as public ID string. */
	  entlen = ustrlen(pubibuf);
	  fpis->fpipubis = pubibuf;
          break;
     default:
          mderr(117, (UNCH *)0, (UNCH *)0);
          return (struct fpi *)0;        /* Signal error to caller. */
     }
     /* PARAMETER 3: System ID literal.
     */
     parm3:
     pcbmd.newstate = 0;
     parsemd(sysibuf, NAMECASE, &pcblitc, LITLEN);
     TRACEMD("3: sys ID literal");
     if (pcbmd.action==LIT || pcbmd.action==LITE) {
          entlen += ustrlen(sysibuf);
	  fpis->fpisysis = sysibuf;
          pcbmd.newstate = 0;
          parsemd(tbuf, NAMECASE, &pcblitp, LITLEN);
     }
     else memcpy(tbuf, sysibuf, *sysibuf);
     if (*estore!=ESF || pcbmd.action!=NAS) goto genfpi;

     /* PARAMETER 4: Entity type keyword.
     */
     TRACEMD("4: Entity type");
     if ((exetype = mapsrch(extettab, tbuf+1))==0) {
          mderr(24, tbuf+1, (UNCH *)0);
          return (struct fpi *)0;
     }
     if (exetype==ESNSUB && SUBDOC == NO) {
	  mderr(90, tbuf+1, (UNCH *)0);
	  return (struct fpi *)0;
     }

     NEXTYPE(pne) = (UNCH)exetype; /* Save entity type in caller's ne. */
     *estore = ESN;                /* Signal that entity is a data entity. */

     if (exetype==ESNSUB) {
          pne->nedcn = 0;
	  pcbmd.newstate = 0;           /* Parse next token for caller. */
	  parsemd(tbuf, NAMECASE, &pcblitp, LITLEN);
	  goto genfpi;
     }
     /* PARAMETER 5: Notation name.
     */
     pcbmd.newstate = 0;
     parsemd(lbuf, NAMECASE, &pcblitp, NAMELEN);
     TRACEMD("5: notation");
     if (pcbmd.action!=NAS) {mderr(119, tbuf+1, (UNCH *)0); return (struct fpi *)0;}
     /* Locate the data content notation. */
     pne->nedcn = dcb = dcndef(lbuf);
     /* Note that we have defined an entity with this notation.
	If attributes are later defined for this notation, we'll
	have to fix up this entity. */
     dcb->entsw = 1;

     /* PARAMETER 6: Data attribute specification.
     */
     pcbmd.newstate = 0;
     parsemd(lbuf, NAMECASE, &pcblitp, NAMELEN);
     TRACEMD("6: [att list]");
     if (pcbmd.action!=MDS) {     /* No attributes specified. */
	  if (dcb->adl == 0)
	       NEAL(pne) = 0;
	  else {
	       initatt(dcb->adl);
	       adlval((int)ADN(al), (struct etd *)0);
	       storedatt(pne);
	  }
          goto genfpi;
     }
     if (dcb->adl==0) {            /* Atts specified, but none defined. */
          mderr(22, (UNCH *)0, (UNCH *)0);
          return (struct fpi *)0;
     }
     pcbstag.newstate = pcbstan;   /* First separator is optional. */
     if ((parseatt(dcb->adl, tbuf))==0)/* Empty list. */
          mderr(91, (UNCH *)0, (UNCH *)0);
     else {
	  adlval((int)ADN(al), (struct etd *)0);
	  storedatt(pne);
     }
     parse(&pcbeal);               /* Parse the list ending. */
     pcbmd.newstate = 0;           /* Parse next token for caller. */
     parsemd(tbuf, NAMECASE, &pcblitp, LITLEN);

     /* GENFPI: Builds a formal public identifier structure, including the
                entity name, offsets of the components of the public ID, and
                other data a system might use to identify the actual file.
     */
 genfpi:
     TRACEMD("7: generate fpi");
     fpis->fpistore = *estore - ESFM + 1;    /* External entity type: 1-6. */
     if (*estore == ESN) {
          if (NEXTYPE(pne) == ESNSUB)
	       fpis->fpinedcn = 0;
	  else
	       fpis->fpinedcn = NEDCN(pne) + 1;
     }
     /* Analyze public ID and make structure entries. */
     if (exidtype==EDPUBLIC) {
          if (FORMAL==NO)
	       fpis->fpiversw = -1;
	  else if (parsefpi(fpis)>0) {
   	       mderr(88, fpis->fpipubis, (UNCH *)0);
               fpis->fpiversw = -1; /* Signal bad formal public ID. */
	  }
     }
     return fpis;
}
コード例 #3
0
ファイル: minixml.c プロジェクト: b1l1s/open-tr069
/* parseelt parse the xml stream and
 * call the callback functions when needed... */
int parseelt(struct xmlparser * p)
{
	int rc;
	unsigned i, nslen, comment;
	const char * elementname, * ns;
	comment = 0;
	while(p->xml < (p->xmlend - 1))
	{
		if (comment) {
			if (p->xml < (p->xmlend - 3) && !strncmp("-->", p->xml, 3)) {
				comment = 0;
			} else {
				p->xml ++;
				continue;
			}
		}
		if((p->xml)[0]=='<' && (p->xml)[1]!='?')
		{
			nslen = 0;
			ns = NULL;
			i = 0; elementname = ++p->xml;
			while( !IS_WHITE_SPACE(*p->xml)
				  && (*p->xml!='>') && (*p->xml!='/')
				 )
			{
				i++; p->xml++;
				if (i == 3 && !strncmp("!--", elementname, 3)) {
					comment = 1;
					break;
				}
				MINIXML_ENSURE_MORE;
				/* to ignore namespace : */
				if(*p->xml==':')
				{
					ns = elementname;
					nslen = i;
					i = 0;
					elementname = ++p->xml;
				}
			}
			if (comment) continue;
			if(i>0)
			{
				if(p->starteltfunc && (rc = p->starteltfunc(
						p->data, ns, nslen, elementname, i)))
					return rc;
				if((rc = parseatt(p)))
					return rc;
				if(*p->xml!='/')
				{
					const char * data;
					i = 0; data = ++p->xml;
					MINIXML_ENSURE_MORE;
					while( IS_WHITE_SPACE(*p->xml) )
					{
						p->xml++;
						MINIXML_ENSURE_MORE;
					}
					while(*p->xml!='<')
					{
						i++; p->xml++;
						MINIXML_ENSURE_MORE;
					}
					if(p->xml<p->xmlend && *(p->xml+1)=='/' && i >= 0 &&
							p->datafunc && (rc = p->datafunc(p->data, data, i)))
						return rc;
				} else {
					if(*(++p->xml) == '>') {
						if(p->endeltfunc && (rc = p->endeltfunc(
								p->data, ns, nslen, elementname, i)))
							return rc;
					} else {
						return -1;
					}
				}
			}
			else if(*p->xml == '/')
			{
				i = 0; elementname = ++p->xml;
				MINIXML_ENSURE_MORE;
				while((*p->xml != '>'))
				{
					i++; p->xml++;
					MINIXML_ENSURE_MORE;
					if(*p->xml==':')
					{
						ns = elementname;
						nslen = i;
						i = 0;
						elementname = ++p->xml;
					}
				}
				if(p->endeltfunc && (rc = p->endeltfunc(
						p->data, ns, nslen, elementname, i)))
					return rc;
				p->xml++;
			}
		}
		else
		{
			p->xml++;
		}
	}
	return 0;
}
コード例 #4
0
ファイル: minixml.c プロジェクト: ICTSTUDIO/ZeroTierOne
/* parseelt parse the xml stream and
 * call the callback functions when needed... */
static void parseelt(struct xmlparser * p)
{
	int i;
	const char * elementname;
	while(p->xml < (p->xmlend - 1))
	{
		if((p->xml + 4) <= p->xmlend && (0 == memcmp(p->xml, "<!--", 4)))
		{
			p->xml += 3;
			/* ignore comments */
			do
			{
				p->xml++;
				if ((p->xml + 3) >= p->xmlend)
					return;
			}
			while(memcmp(p->xml, "-->", 3) != 0);
			p->xml += 3;
		}
		else if((p->xml)[0]=='<' && (p->xml)[1]!='?')
		{
			i = 0; elementname = ++p->xml;
			while( !IS_WHITE_SPACE(*p->xml)
				  && (*p->xml!='>') && (*p->xml!='/')
				 )
			{
				i++; p->xml++;
				if (p->xml >= p->xmlend)
					return;
				/* to ignore namespace : */
				if(*p->xml==':')
				{
					i = 0;
					elementname = ++p->xml;
				}
			}
			if(i>0)
			{
				if(p->starteltfunc)
					p->starteltfunc(p->data, elementname, i);
				if(parseatt(p))
					return;
				if(*p->xml!='/')
				{
					const char * data;
					i = 0; data = ++p->xml;
					if (p->xml >= p->xmlend)
						return;
					while( IS_WHITE_SPACE(*p->xml) )
					{
						i++; p->xml++;
						if (p->xml >= p->xmlend)
							return;
					}
					if(memcmp(p->xml, "<![CDATA[", 9) == 0)
					{
						/* CDATA handling */
						p->xml += 9;
						data = p->xml;
						i = 0;
						while(memcmp(p->xml, "]]>", 3) != 0)
						{
							i++; p->xml++;
							if ((p->xml + 3) >= p->xmlend)
								return;
						}
						if(i>0 && p->datafunc)
							p->datafunc(p->data, data, i);
						while(*p->xml!='<')
						{
							p->xml++;
							if (p->xml >= p->xmlend)
								return;
						}
					}
					else
					{
						while(*p->xml!='<')
						{
							i++; p->xml++;
							if ((p->xml + 1) >= p->xmlend)
								return;
						}
						if(i>0 && p->datafunc && *(p->xml + 1) == '/')
							p->datafunc(p->data, data, i);
					}
				}
			}
			else if(*p->xml == '/')
			{
				i = 0; elementname = ++p->xml;
				if (p->xml >= p->xmlend)
					return;
				while((*p->xml != '>'))
				{
					i++; p->xml++;
					if (p->xml >= p->xmlend)
						return;
				}
				if(p->endeltfunc)
					p->endeltfunc(p->data, elementname, i);
				p->xml++;
			}
		}
		else
		{
			p->xml++;
		}
	}
}