--- truecrypt/common/xml.c 2018/04/24 16:44:39 1.1.1.2 +++ truecrypt/common/xml.c 2018/04/24 16:46:28 1.1.1.4 @@ -1,8 +1,9 @@ -/* -Copyright (c) 2004-2006 TrueCrypt Foundation. All rights reserved. +/* + Copyright (c) TrueCrypt Foundation. All rights reserved. -Covered by TrueCrypt License 2.0 the full text of which is contained in the file -License.txt included in TrueCrypt binary and source code distribution archives. + Covered by the TrueCrypt License 2.2 the full text of which is contained + in the file License.txt included in TrueCrypt binary and source code + distribution packages. */ #include @@ -60,7 +61,7 @@ char *XmlFindElementByAttributeValue (ch while (xml = XmlFindElement (xml, nodeName)) { - XmlAttribute (xml, attrName, attr, sizeof (attr)); + XmlGetAttributeText (xml, attrName, attr, sizeof (attr)); if (strcmp (attr, attrValue) == 0) return xml; @@ -71,7 +72,7 @@ char *XmlFindElementByAttributeValue (ch } -char *XmlAttribute (char *xmlNode, char *xmlAttrName, char *xmlAttrValue, int xmlAttrValueSize) +char *XmlGetAttributeText (char *xmlNode, char *xmlAttrName, char *xmlAttrValue, int xmlAttrValueSize) { char *t = xmlNode; char *e = xmlNode; @@ -112,7 +113,7 @@ char *XmlAttribute (char *xmlNode, char } -char *XmlNodeText (char *xmlNode, char *xmlText, int xmlTextSize) +char *XmlGetNodeText (char *xmlNode, char *xmlText, int xmlTextSize) { char *t = xmlNode; char *e = xmlNode + 1; @@ -160,6 +161,52 @@ char *XmlNodeText (char *xmlNode, char * } +char *XmlQuoteText (char *textSrc, char *textDst, int textDstMaxSize) +{ + char *textDstLast = textDst + textDstMaxSize - 1; + + if (textDstMaxSize == 0) + return NULL; + + while (*textSrc != 0 && textDst <= textDstLast) + { + char c = *textSrc++; + switch (c) + { + case '&': + if (textDst + 6 > textDstLast) + return NULL; + strcpy (textDst, "&"); + textDst += 5; + continue; + + case '>': + if (textDst + 5 > textDstLast) + return NULL; + strcpy (textDst, ">"); + textDst += 4; + continue; + + case '<': + if (textDst + 5 > textDstLast) + return NULL; + strcpy (textDst, "<"); + textDst += 4; + continue; + + default: + *textDst++ = c; + } + } + + if (textDst > textDstLast) + return NULL; + + *textDst = 0; + return textDst; +} + + int XmlWriteHeader (FILE *file) { return fputs ("\n", file);