2020-03-26 01:12:32 +01:00
|
|
|
|
|
|
|
struct _tag
|
2018-05-20 15:40:58 +02:00
|
|
|
{
|
2020-03-26 01:12:32 +01:00
|
|
|
char name[32];
|
2020-03-27 21:18:44 +01:00
|
|
|
char prior[32];
|
2020-03-26 01:12:32 +01:00
|
|
|
bool opened;
|
|
|
|
collection attributes;
|
|
|
|
collection values;
|
2020-12-18 00:01:09 +01:00
|
|
|
dword value;
|
2020-03-26 01:12:32 +01:00
|
|
|
bool is();
|
2020-12-18 02:47:36 +01:00
|
|
|
bool parse();
|
2020-12-18 00:01:09 +01:00
|
|
|
void debug_tag();
|
2020-12-18 02:47:36 +01:00
|
|
|
dword get_next_param();
|
2020-03-26 01:12:32 +01:00
|
|
|
dword get_value_of();
|
2020-05-23 13:26:58 +02:00
|
|
|
} tag=0;
|
2018-05-20 15:40:58 +02:00
|
|
|
|
2020-03-26 01:12:32 +01:00
|
|
|
bool _tag::is(dword _text)
|
|
|
|
{
|
2020-12-18 00:01:09 +01:00
|
|
|
if ( !strcmp(#name, _text) ) {
|
2020-03-26 01:12:32 +01:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-18 02:47:36 +01:00
|
|
|
bool _tag::parse(dword _bufpos, bufend)
|
2020-03-26 01:12:32 +01:00
|
|
|
{
|
2020-12-18 00:01:09 +01:00
|
|
|
bool retok = true;
|
|
|
|
dword bufpos = ESDWORD[_bufpos];
|
2020-12-18 02:47:36 +01:00
|
|
|
dword params, paramsend;
|
2020-12-18 00:01:09 +01:00
|
|
|
|
|
|
|
dword closepos;
|
|
|
|
dword whitepos;
|
|
|
|
|
|
|
|
if (name) strcpy(#prior, #name); else prior = '\0';
|
|
|
|
name = '\0';
|
2020-03-26 01:12:32 +01:00
|
|
|
attributes.drop();
|
2020-12-18 00:01:09 +01:00
|
|
|
values.drop();
|
|
|
|
|
|
|
|
if (!strncmp(bufpos,"!--",3))
|
|
|
|
{
|
|
|
|
bufpos+=3;
|
|
|
|
//STRSTR
|
|
|
|
while (strncmp(bufpos,"-->",3)!=0) && (bufpos < bufend)
|
|
|
|
{
|
|
|
|
bufpos++;
|
|
|
|
}
|
|
|
|
bufpos+=2;
|
2020-12-18 02:47:36 +01:00
|
|
|
retok = false;
|
2020-12-18 00:01:09 +01:00
|
|
|
goto _RET;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ESBYTE[bufpos] == '/') {
|
|
|
|
opened = false;
|
|
|
|
bufpos++;
|
|
|
|
} else {
|
|
|
|
opened = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
closepos = strchr(bufpos, '>');
|
|
|
|
whitepos = strchrw(bufpos, bufend-bufpos);
|
2020-12-18 02:47:36 +01:00
|
|
|
|
|
|
|
if (debug_mode) {
|
|
|
|
if (!closepos) debugln("null closepos");
|
|
|
|
if (!whitepos) debugln("null whitepos");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!whitepos) || (whitepos > closepos) {
|
2020-12-18 00:01:09 +01:00
|
|
|
//no param
|
|
|
|
strncpy(#name, bufpos, math.min(closepos - bufpos, sizeof(tag.name)));
|
|
|
|
debug_tag();
|
|
|
|
bufpos = closepos;
|
|
|
|
} else {
|
|
|
|
//we have param
|
|
|
|
strncpy(#name, bufpos, math.min(whitepos - bufpos, sizeof(tag.name)));
|
|
|
|
debug_tag();
|
|
|
|
bufpos = closepos;
|
|
|
|
|
2020-12-18 02:47:36 +01:00
|
|
|
params = malloc(closepos - whitepos + 1);
|
|
|
|
strncpy(params, whitepos, closepos - whitepos);
|
|
|
|
if (debug_mode) { debug("params: "); debugln(params+1); }
|
|
|
|
paramsend = params + closepos - whitepos;
|
|
|
|
while (paramsend = get_next_param(params, paramsend-1));
|
|
|
|
free(params);
|
2020-12-18 00:01:09 +01:00
|
|
|
}
|
|
|
|
|
2020-12-18 02:47:36 +01:00
|
|
|
if (name) {
|
|
|
|
strlwr(#name);
|
|
|
|
// ignore text inside the next tags
|
|
|
|
if (is("script")) || (is("style")) || (is("binary")) || (is("select")) {
|
|
|
|
strcpy(#prior, #name);
|
|
|
|
sprintf(#name, "</%s>", #prior);
|
|
|
|
if (strstri(bufpos, #name)) bufpos = EAX-1;
|
|
|
|
retok = false;
|
|
|
|
} else {
|
|
|
|
if (name[strlen(#name)-1]=='/') name[strlen(#name)-1]=NULL; //for <br/>
|
|
|
|
}
|
|
|
|
} else {
|
2020-12-18 00:01:09 +01:00
|
|
|
retok = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
_RET:
|
|
|
|
ESDWORD[_bufpos] = bufpos;
|
|
|
|
return retok;
|
2020-03-26 01:12:32 +01:00
|
|
|
}
|
|
|
|
|
2020-12-18 00:01:09 +01:00
|
|
|
void _tag::debug_tag()
|
2020-03-26 01:12:32 +01:00
|
|
|
{
|
2020-12-18 00:01:09 +01:00
|
|
|
if (debug_mode) {
|
|
|
|
debugch('<');
|
|
|
|
if (!opened) debugch('/');
|
|
|
|
debug(#name);
|
|
|
|
debugln(">");
|
|
|
|
}
|
2020-03-26 01:12:32 +01:00
|
|
|
}
|
2018-05-20 15:40:58 +02:00
|
|
|
|
2020-12-18 02:47:36 +01:00
|
|
|
dword _tag::get_next_param(dword ps, pe)
|
2020-03-26 01:12:32 +01:00
|
|
|
{
|
2020-12-18 02:47:36 +01:00
|
|
|
// "ps" - param start
|
|
|
|
// "pe" - param end
|
|
|
|
// "q" - quote char
|
|
|
|
char q = NULL;
|
|
|
|
dword fixeq;
|
2020-12-18 16:39:38 +01:00
|
|
|
dword val;
|
2020-12-18 12:41:33 +01:00
|
|
|
dword attr;
|
2020-03-26 01:12:32 +01:00
|
|
|
|
2020-12-18 02:47:36 +01:00
|
|
|
if (ESBYTE[pe] == '/') pe--;
|
|
|
|
while (pe>ps) && (__isWhite(ESBYTE[pe])) pe--;
|
2018-05-20 15:40:58 +02:00
|
|
|
|
2020-12-18 02:47:36 +01:00
|
|
|
if (ESBYTE[pe] == '"') || (ESBYTE[pe] == '\'')
|
2018-05-20 15:40:58 +02:00
|
|
|
{
|
2020-12-18 02:47:36 +01:00
|
|
|
//remove quote
|
|
|
|
q = ESBYTE[pe];
|
|
|
|
ESBYTE[pe] = '\0';
|
|
|
|
pe--;
|
2018-05-20 15:40:58 +02:00
|
|
|
|
|
|
|
//find VAL start and copy
|
2020-12-18 02:47:36 +01:00
|
|
|
pe = strrchr(ps, q) + ps;
|
2020-12-18 16:39:38 +01:00
|
|
|
val = pe;
|
2020-12-18 02:47:36 +01:00
|
|
|
pe--;
|
2020-12-18 16:39:38 +01:00
|
|
|
ESBYTE[pe] = '\0';
|
2018-05-20 15:40:58 +02:00
|
|
|
|
|
|
|
//find ATTR end
|
2020-12-18 02:47:36 +01:00
|
|
|
while (pe > ps) && (ESBYTE[pe] != '=') pe--;
|
2020-12-18 13:55:55 +01:00
|
|
|
ESBYTE[pe] = '\0';
|
2018-05-20 15:40:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//find VAL start and copy
|
2020-12-18 02:47:36 +01:00
|
|
|
while (pe > ps) && (ESBYTE[pe] != '=') pe--;
|
2020-12-18 16:39:38 +01:00
|
|
|
val = pe+1;
|
2020-12-18 13:55:55 +01:00
|
|
|
ESBYTE[pe] = '\0';
|
2020-03-26 01:12:32 +01:00
|
|
|
//already have ATTR end
|
2018-05-20 15:40:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//find ATTR start and copy
|
2020-12-18 02:47:36 +01:00
|
|
|
while (pe>ps) && (!__isWhite(ESBYTE[pe])) pe--;
|
2020-12-18 12:41:33 +01:00
|
|
|
attr = pe + 1;
|
2020-12-18 02:47:36 +01:00
|
|
|
ESBYTE[pe] = '\0';
|
2020-12-18 16:39:38 +01:00
|
|
|
|
|
|
|
// Fix case: src=./images/logo?sid=e8ece8b38b
|
|
|
|
// Exchange '=' and '\0' position.
|
|
|
|
// attr: src=./images/logo?sid => src
|
|
|
|
// val: e8ece8b38b => ./images/logo?sid=e8ece8b38b
|
2020-12-18 12:41:33 +01:00
|
|
|
fixeq = strchr(attr,'=');
|
2020-12-18 02:47:36 +01:00
|
|
|
if (!q) && (fixeq) {
|
2020-12-18 16:39:38 +01:00
|
|
|
ESBYTE[val-1] >< ESBYTE[fixeq];
|
|
|
|
val = fixeq+1;
|
2020-03-25 01:18:19 +01:00
|
|
|
}
|
2020-12-18 12:41:33 +01:00
|
|
|
strlwr(attr);
|
2020-12-18 16:39:38 +01:00
|
|
|
strrtrim(val);
|
2018-05-20 15:40:58 +02:00
|
|
|
|
2020-12-18 12:41:33 +01:00
|
|
|
attributes.add(attr);
|
2020-12-18 16:39:38 +01:00
|
|
|
values.add(val);
|
2018-05-20 15:40:58 +02:00
|
|
|
|
2020-12-18 00:01:09 +01:00
|
|
|
if (debug_mode) {
|
2020-12-18 12:41:33 +01:00
|
|
|
debug("atr: "); debugln(attr);
|
2020-12-18 16:39:38 +01:00
|
|
|
debug("val: "); debugln(val);
|
2020-12-18 00:01:09 +01:00
|
|
|
debugch('\n');
|
|
|
|
}
|
|
|
|
|
2020-12-18 02:47:36 +01:00
|
|
|
if (pe==ps) return NULL;
|
|
|
|
return pe;
|
2018-05-20 15:40:58 +02:00
|
|
|
}
|
|
|
|
|
2020-03-26 01:12:32 +01:00
|
|
|
dword _tag::get_value_of(dword _attr_name)
|
|
|
|
{
|
|
|
|
int pos = attributes.get_pos_by_name(_attr_name);
|
|
|
|
if (pos == -1) {
|
2020-12-18 00:01:09 +01:00
|
|
|
value = 0;
|
2020-03-26 01:12:32 +01:00
|
|
|
} else {
|
2020-12-18 00:01:09 +01:00
|
|
|
value = values.get(pos);
|
2020-03-26 01:12:32 +01:00
|
|
|
}
|
2020-12-18 00:01:09 +01:00
|
|
|
return value;
|
2020-03-26 01:12:32 +01:00
|
|
|
}
|