--- truecrypt/common/xml.c 2018/04/24 16:44:39 1.1.1.2 +++ truecrypt/common/xml.c 2018/04/24 17:08:09 1.1.1.12 @@ -1,8 +1,9 @@ -/* -Copyright (c) 2004-2006 TrueCrypt Foundation. All rights reserved. +/* + Copyright (c) 2005-2010 TrueCrypt Developers Association. 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. + Governed by the TrueCrypt License 3.0 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,9 +161,61 @@ char *XmlNodeText (char *xmlNode, char * } +char *XmlQuoteText (const 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); + return fputs ("\n", file); +} + + +int XmlWriteHeaderW (FILE *file) +{ + return fputws (L"\n", file); } @@ -170,3 +223,9 @@ int XmlWriteFooter (FILE *file) { return fputs ("\n", file); } + + +int XmlWriteFooterW (FILE *file) +{ + return fputws (L"\n", file); +}