VeraCrypt
aboutsummaryrefslogtreecommitdiff
path: root/src/Common/Xml.c
diff options
context:
space:
mode:
authorMounir IDRASSI <mounir.idrassi@idrix.fr>2015-11-25 01:41:37 +0100
committerMounir IDRASSI <mounir.idrassi@idrix.fr>2015-11-26 01:44:52 +0100
commit90bd57fe40e66fc829ecb01482d32d604b0df19c (patch)
tree6d6de0d9a31c82d0598f68c2d160cb9e565bd5ea /src/Common/Xml.c
parentec7d96fcb733021c214b414a1ba2841039733dd2 (diff)
downloadVeraCrypt-90bd57fe40e66fc829ecb01482d32d604b0df19c.tar.gz
VeraCrypt-90bd57fe40e66fc829ecb01482d32d604b0df19c.zip
Windows: Full UNICODE rewrite and implement support for UNICODE passwords.
Diffstat (limited to 'src/Common/Xml.c')
-rw-r--r--src/Common/Xml.c53
1 files changed, 43 insertions, 10 deletions
diff --git a/src/Common/Xml.c b/src/Common/Xml.c
index bd01460b..71994510 100644
--- a/src/Common/Xml.c
+++ b/src/Common/Xml.c
@@ -210,26 +210,59 @@ char *XmlQuoteText (const char *textSrc, char *textDst, int textDstMaxSize)
return textDst;
}
-
-int XmlWriteHeader (FILE *file)
+wchar_t *XmlQuoteTextW (const wchar_t *textSrc, wchar_t *textDst, int textDstMaxSize)
{
- return fputs ("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<VeraCrypt>", file);
-}
+ wchar_t *textDstLast = textDst + textDstMaxSize - 1;
+ if (textDstMaxSize == 0)
+ return NULL;
-int XmlWriteHeaderW (FILE *file)
-{
- return fputws (L"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<VeraCrypt>", file);
+ while (*textSrc != 0 && textDst <= textDstLast)
+ {
+ wchar_t c = *textSrc++;
+ switch (c)
+ {
+ case L'&':
+ if (textDst + 6 > textDstLast)
+ return NULL;
+ wcscpy (textDst, L"&amp;");
+ textDst += 5;
+ continue;
+
+ case L'>':
+ if (textDst + 5 > textDstLast)
+ return NULL;
+ wcscpy (textDst, L"&gt;");
+ textDst += 4;
+ continue;
+
+ case L'<':
+ if (textDst + 5 > textDstLast)
+ return NULL;
+ wcscpy (textDst, L"&lt;");
+ textDst += 4;
+ continue;
+
+ default:
+ *textDst++ = c;
+ }
+ }
+
+ if (textDst > textDstLast)
+ return NULL;
+
+ *textDst = 0;
+ return textDst;
}
-int XmlWriteFooter (FILE *file)
+int XmlWriteHeader (FILE *file)
{
- return fputs ("\n</VeraCrypt>", file);
+ return fputws (L"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<VeraCrypt>", file);
}
-int XmlWriteFooterW (FILE *file)
+int XmlWriteFooter (FILE *file)
{
return fputws (L"\n</VeraCrypt>", file);
}