Kaydet (Commit) 215c1376 authored tarafından Ali Rıza KESKİN's avatar Ali Rıza KESKİN

Hardy optimized.

üst cb49cf72
/* iksemel (XML parser for Jabber) /* iksemel (XML parser for Jabber)
** Copyright (C) 2000-2003 Gurer Ozen <madcat@e-kolay.net> ** Copyright (C) 2000-2003 Gurer Ozen <madcat@e-kolay.net>
** Modification 2016-2020 Ali Rıza Keskin <parduscix@yandex.ru>
** This code is free software; you can redistribute it and/or ** This code is free software; you can redistribute it and/or
** modify it under the terms of GNU Lesser General Public License. ** modify it under the terms of GNU Lesser General Public License.
*/ */
...@@ -652,68 +653,75 @@ sax_core (iksparser *prs, char *buf, int len) ...@@ -652,68 +653,75 @@ sax_core (iksparser *prs, char *buf, int len)
switch (prs->context) { switch (prs->context) {
case C_CDATA: case C_CDATA:
if ('&' == c) { switch(c){
if (old < pos && prs->cdataHook) { case '&':
err = prs->cdataHook (prs->user_data, &buf[old], pos - old); if (old < pos && prs->cdataHook) {
if (IKS_OK != err) return err; err = prs->cdataHook (prs->user_data, &buf[old], pos - old);
} if (IKS_OK != err) return err;
prs->context = C_ENTITY; }
prs->entpos = 0; prs->context = C_ENTITY;
break; prs->entpos = 0;
}else if ('<' == c) { break;
if (old < pos && prs->cdataHook) { case '<':
err = prs->cdataHook (prs->user_data, &buf[old], pos - old); if (old < pos && prs->cdataHook) {
if (IKS_OK != err) return err; err = prs->cdataHook (prs->user_data, &buf[old], pos - old);
} if (IKS_OK != err) return err;
STACK_INIT; }
prs->tag_name = STACK_PUSH_START; STACK_INIT;
if (!prs->tag_name) return IKS_NOMEM; prs->tag_name = STACK_PUSH_START;
prs->context = C_TAG_START; if (!prs->tag_name) return IKS_NOMEM;
prs->context = C_TAG_START;
break;
} }
break; break;
case C_TAG_START: case C_TAG_START:
prs->context = C_TAG; prs->context = C_TAG;
if ('/' == c) { switch(c){
prs->tagtype = IKS_CLOSE; case '/':
break; prs->tagtype = IKS_CLOSE;
}else if ('?' == c) { break;
prs->context = C_PI; case '?':
break; prs->context = C_PI;
}else if ('!' == c) { break;
prs->context = C_MARKUP; case '!':
break; prs->context = C_MARKUP;
break;
} }
prs->tagtype = IKS_OPEN; prs->tagtype = IKS_OPEN;
stack_old = pos; stack_old = pos;
break; break;
case C_TAG: case C_TAG:
if (IS_WHITESPACE(c)) { switch(c){
if (IKS_CLOSE == prs->tagtype) case ' ':
prs->oldcontext = C_TAG_END; case '\t':
else case '\r':
prs->oldcontext = C_ATTRIBUTE; case '\n':
prs->context = C_WHITESPACE; if (IKS_CLOSE == prs->tagtype)
if (stack_old != -1) STACK_PUSH (buf + stack_old, pos - stack_old); prs->oldcontext = C_TAG_END;
stack_old = -1; else
STACK_PUSH_END; prs->oldcontext = C_ATTRIBUTE;
break; prs->context = C_WHITESPACE;
}else if ('/' == c) { if (stack_old != -1) STACK_PUSH (buf + stack_old, pos - stack_old);
if (IKS_CLOSE == prs->tagtype) return IKS_BADXML; stack_old = -1;
prs->tagtype = IKS_SINGLE; STACK_PUSH_END;
prs->context = C_TAG_END; break;
if (stack_old != -1) STACK_PUSH (buf + stack_old, pos - stack_old); case '/':
stack_old = -1; if (IKS_CLOSE == prs->tagtype) return IKS_BADXML;
STACK_PUSH_END; prs->tagtype = IKS_SINGLE;
break; prs->context = C_TAG_END;
}else if ('>' == c) { if (stack_old != -1) STACK_PUSH (buf + stack_old, pos - stack_old);
prs->context = C_TAG_END; stack_old = -1;
if (stack_old != -1) STACK_PUSH (buf + stack_old, pos - stack_old); STACK_PUSH_END;
stack_old = -1; break;
STACK_PUSH_END; case '>':
re = 1; prs->context = C_TAG_END;
break; if (stack_old != -1) STACK_PUSH (buf + stack_old, pos - stack_old);
stack_old = -1;
STACK_PUSH_END;
re = 1;
break;
} }
if (stack_old == -1) stack_old = pos; if (stack_old == -1) stack_old = pos;
break; break;
...@@ -735,11 +743,12 @@ sax_core (iksparser *prs, char *buf, int len) ...@@ -735,11 +743,12 @@ sax_core (iksparser *prs, char *buf, int len)
break; break;
case C_ATTRIBUTE: case C_ATTRIBUTE:
if ('/' == c) { switch(c){
case '/':
prs->tagtype = IKS_SINGLE; prs->tagtype = IKS_SINGLE;
prs->context = C_TAG_END; prs->context = C_TAG_END;
break; break;
}else if ('>' == c) { case '>':
prs->context = C_TAG_END; prs->context = C_TAG_END;
re = 1; re = 1;
break; break;
...@@ -780,16 +789,17 @@ sax_core (iksparser *prs, char *buf, int len) ...@@ -780,16 +789,17 @@ sax_core (iksparser *prs, char *buf, int len)
break; break;
case C_ATTRIBUTE_2: case C_ATTRIBUTE_2:
if ('/' == c) { switch(c){
prs->tagtype = IKS_SINGLE; case '/':
prs->atts[prs->attcur] = NULL; prs->tagtype = IKS_SINGLE;
prs->context = C_TAG_END; prs->atts[prs->attcur] = NULL;
break; prs->context = C_TAG_END;
}else if ('>' == c) { break;
prs->atts[prs->attcur] = NULL; case '>':
prs->context = C_TAG_END; prs->atts[prs->attcur] = NULL;
re = 1; prs->context = C_TAG_END;
break; re = 1;
break;
} }
prs->context = C_ATTRIBUTE; prs->context = C_ATTRIBUTE;
re = 1; re = 1;
...@@ -797,12 +807,13 @@ sax_core (iksparser *prs, char *buf, int len) ...@@ -797,12 +807,13 @@ sax_core (iksparser *prs, char *buf, int len)
case C_VALUE: case C_VALUE:
prs->atts[prs->attcur + 1] = STACK_PUSH_START; prs->atts[prs->attcur + 1] = STACK_PUSH_START;
if ('\'' == c) { switch(c){
prs->context = C_VALUE_APOS; case '\'':
break; prs->context = C_VALUE_APOS;
}else if ('"' == c) { break;
prs->context = C_VALUE_QUOT; case '\"':
break; prs->context = C_VALUE_QUOT;
break;
} }
return IKS_BADXML; return IKS_BADXML;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment