[esnacc-dev] [PATCH 01/11] cxx-lib/asn-octs: Improve XML printing

Aaron Conole aconole at bytheb.org
Tue Dec 6 19:46:59 UTC 2016


The OCTET-STRING class output invalid xml, which doesn't comply fully
with XER.  To correct this, we need to do the following:

1) In the untyped case, remove the dash (which is not valid), and use an
   underscore.

2) In both cases, print the data as hex data.

Signed-off-by: Aaron Conole <aconole at bytheb.org>
---
 cxx-lib/src/asn-octs.cpp | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/cxx-lib/src/asn-octs.cpp b/cxx-lib/src/asn-octs.cpp
index 22c41bc..02d7795 100644
--- a/cxx-lib/src/asn-octs.cpp
+++ b/cxx-lib/src/asn-octs.cpp
@@ -86,18 +86,22 @@ void AsnOcts::Set (const char *str, size_t len)
 void AsnOcts::PrintXML (std::ostream &os, const char *lpszTitle,
                         const char *lpszType) const
 {
-    const char *tagName = "OCTET-STRING";
+    const char *tagName = "OCTET_STRING";
     if (lpszType)
         tagName = lpszType;
     os << "<" << tagName << ">";
 
-   os << "-";
-   Print(os);
-   //PrintXMLSupport(&os, ((AsnOcts *)this)->Access(), octetLen);
-   if (lpszType)
-     os << "</" << lpszType << ">\n";
-   else
-     os << "</OCTET_STRING>\n";
+    std::ios_base::fmtflags old_flags = os.flags();
+    os << std::hex;
+    for (size_t i = 0; i < Len(); ++i) {
+        os << (unsigned int)(c_ustr()[i]);
+    }
+    os.flags(old_flags);
+
+    if (lpszType)
+        os << "</" << lpszType << ">\n";
+    else
+        os << "</OCTET_STRING>\n";
 }
 
 // Prints the AsnOcts to the given ostream in Value Notation.
-- 
2.7.4




More information about the dev mailing list