[core] Save position of XML opening tag '>' and XML closing tag '<' in switch_xml_parse_str().
This commit is contained in:
parent
047c3c7217
commit
8e17dca00d
|
@ -102,6 +102,10 @@ struct switch_xml {
|
||||||
/*! is_switch_xml_root bool */
|
/*! is_switch_xml_root bool */
|
||||||
switch_bool_t is_switch_xml_root_t;
|
switch_bool_t is_switch_xml_root_t;
|
||||||
uint32_t refs;
|
uint32_t refs;
|
||||||
|
/*! pointer to end of opening tag, '>', in the original parsed text */
|
||||||
|
const char *open;
|
||||||
|
/*! pointer to start of closing tag, '<', in the original parsed text */
|
||||||
|
const char *close;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|
|
@ -684,7 +684,7 @@ static char *switch_xml_decode(char *s, char **ent, char t)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* called when parser finds start of new tag */
|
/* called when parser finds start of new tag */
|
||||||
static void switch_xml_open_tag(switch_xml_root_t root, char *name, char **attr)
|
static void switch_xml_open_tag(switch_xml_root_t root, char *name, char *open_pos, char **attr)
|
||||||
{
|
{
|
||||||
switch_xml_t xml;
|
switch_xml_t xml;
|
||||||
|
|
||||||
|
@ -701,6 +701,7 @@ static void switch_xml_open_tag(switch_xml_root_t root, char *name, char **attr)
|
||||||
|
|
||||||
xml->attr = attr;
|
xml->attr = attr;
|
||||||
root->cur = xml; /* update tag insertion point */
|
root->cur = xml; /* update tag insertion point */
|
||||||
|
root->cur->open = open_pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* called when parser finds character content between open and closing tag */
|
/* called when parser finds character content between open and closing tag */
|
||||||
|
@ -742,11 +743,12 @@ static void switch_xml_char_content(switch_xml_root_t root, char *s, switch_size
|
||||||
}
|
}
|
||||||
|
|
||||||
/* called when parser finds closing tag */
|
/* called when parser finds closing tag */
|
||||||
static switch_xml_t switch_xml_close_tag(switch_xml_root_t root, char *name, char *s)
|
static switch_xml_t switch_xml_close_tag(switch_xml_root_t root, char *name, char *s, char *close_pos)
|
||||||
{
|
{
|
||||||
if (!root || !root->cur || !root->cur->name || strcmp(name, root->cur->name))
|
if (!root || !root->cur || !root->cur->name || strcmp(name, root->cur->name))
|
||||||
return switch_xml_err(root, s, "unexpected closing tag </%s>", name);
|
return switch_xml_err(root, s, "unexpected closing tag </%s>", name);
|
||||||
|
|
||||||
|
root->cur->close = close_pos;
|
||||||
root->cur = root->cur->parent;
|
root->cur = root->cur->parent;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1118,11 +1120,11 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_str(char *s, switch_size_t len)
|
||||||
switch_xml_free_attr(attr);
|
switch_xml_free_attr(attr);
|
||||||
return switch_xml_err(root, d, "missing >");
|
return switch_xml_err(root, d, "missing >");
|
||||||
}
|
}
|
||||||
switch_xml_open_tag(root, d, attr);
|
switch_xml_open_tag(root, d, s + 1, attr);
|
||||||
switch_xml_close_tag(root, d, s);
|
switch_xml_close_tag(root, d, s, NULL);
|
||||||
} else if ((q = *s) == '>' || (!*s && e == '>')) { /* open tag */
|
} else if ((q = *s) == '>' || (!*s && e == '>')) { /* open tag */
|
||||||
*s = '\0'; /* temporarily null terminate tag name */
|
*s = '\0'; /* temporarily null terminate tag name */
|
||||||
switch_xml_open_tag(root, d, attr);
|
switch_xml_open_tag(root, d, s, attr);
|
||||||
*s = q;
|
*s = q;
|
||||||
} else {
|
} else {
|
||||||
if (l)
|
if (l)
|
||||||
|
@ -1130,11 +1132,12 @@ SWITCH_DECLARE(switch_xml_t) switch_xml_parse_str(char *s, switch_size_t len)
|
||||||
return switch_xml_err(root, d, "missing >");
|
return switch_xml_err(root, d, "missing >");
|
||||||
}
|
}
|
||||||
} else if (*s == '/') { /* close tag */
|
} else if (*s == '/') { /* close tag */
|
||||||
|
char *close_pos = d - 1;
|
||||||
s += strcspn(d = s + 1, SWITCH_XML_WS ">") + 1;
|
s += strcspn(d = s + 1, SWITCH_XML_WS ">") + 1;
|
||||||
if (!(q = *s) && e != '>')
|
if (!(q = *s) && e != '>')
|
||||||
return switch_xml_err(root, d, "missing >");
|
return switch_xml_err(root, d, "missing >");
|
||||||
*s = '\0'; /* temporarily null terminate tag name */
|
*s = '\0'; /* temporarily null terminate tag name */
|
||||||
if (switch_xml_close_tag(root, d, s))
|
if (switch_xml_close_tag(root, d, s, close_pos))
|
||||||
return &root->xml;
|
return &root->xml;
|
||||||
if (isspace((int) (*s = q)))
|
if (isspace((int) (*s = q)))
|
||||||
s += strspn(s, SWITCH_XML_WS);
|
s += strspn(s, SWITCH_XML_WS);
|
||||||
|
|
Loading…
Reference in New Issue