use libzypp xml::escape
authorMichael Andres <ma@suse.de>
Thu, 23 Jan 2014 14:15:59 +0000 (15:15 +0100)
committerMichael Andres <ma@suse.de>
Thu, 23 Jan 2014 14:34:16 +0000 (15:34 +0100)
src/Summary.cc
src/output/OutXML.cc
src/repos.cc
src/update.cc
src/utils/misc.cc
src/utils/misc.h

index 7a69379..f0e2bdf 100644 (file)
@@ -1317,9 +1317,9 @@ void Summary::writeXmlResolvableList(ostream & out, const KindToResPairSet & res
         out << " arch-old=\"" << rold->arch() << "\"";
       }
       if (!res->summary().empty())
-        out << " summary=\"" << xml_encode(res->summary()) << "\"";
+        out << " summary=\"" << xml::escape(res->summary()) << "\"";
       if (!res->description().empty())
-        out << ">" << endl << xml_encode(res->description()) << "</solvable>" << endl;
+        out << ">" << endl << xml::escape(res->description()) << "</solvable>" << endl;
       else
         out << "/>" << endl;
     }
index 9c21fc7..58261e9 100644 (file)
@@ -77,7 +77,7 @@ void OutXML::info(const string & msg, Verbosity verbosity, Type mask)
   if (infoWarningFilter(verbosity, mask))
     return;
 
-  cout << "<message type=\"info\">" << xml_encode(msg)
+  cout << "<message type=\"info\">" << xml::escape(msg)
        << "</message>" << endl;
 }
 
@@ -86,13 +86,13 @@ void OutXML::warning(const string & msg, Verbosity verbosity, Type mask)
   if (infoWarningFilter(verbosity, mask))
     return;
 
-  cout << "<message type=\"warning\">" << xml_encode(msg)
+  cout << "<message type=\"warning\">" << xml::escape(msg)
        << "</message>" << endl;
 }
 
 void OutXML::error(const string & problem_desc, const string & hint)
 {
-  cout << "<message type=\"error\">" << xml_encode(problem_desc)
+  cout << "<message type=\"error\">" << xml::escape(problem_desc)
        << "</message>" << endl;
   //! \todo hint
 }
@@ -111,7 +111,7 @@ void OutXML::error(const zypp::Exception & e,
   if (!hint.empty())
     s << hint << endl;
 
-  cout << "<message type=\"error\">" << xml_encode(s.str())
+  cout << "<message type=\"error\">" << xml::escape(s.str())
        << "</message>" << endl;
 }
 
@@ -119,8 +119,8 @@ void OutXML::writeProgressTag(const string & id, const string & label,
                               int value, bool done, bool error)
 {
   cout << "<progress";
-  cout << " id=\"" << xml_encode(id) << "\"";
-  cout << " name=\"" << xml_encode(label) << "\"";
+  cout << " id=\"" << xml::escape(id) << "\"";
+  cout << " name=\"" << xml::escape(label) << "\"";
   if (done)
     cout << " done=\"" << error << "\"";
   // print value only if it is known (percentage progress)
@@ -162,7 +162,7 @@ void OutXML::progressEnd(const string & id, const string& label, bool error)
 void OutXML::dwnldProgressStart(const zypp::Url & uri)
 {
   cout << "<download"
-    << " url=\"" << xml_encode(uri.asString()) << "\""
+    << " url=\"" << xml::escape(uri.asString()) << "\""
     << " percent=\"-1\""
     << " rate=\"-1\""
     << "/>" << endl;
@@ -173,7 +173,7 @@ void OutXML::dwnldProgress(const zypp::Url & uri,
                            long rate)
 {
   cout << "<download"
-    << " url=\"" << xml_encode(uri.asString()) << "\""
+    << " url=\"" << xml::escape(uri.asString()) << "\""
     << " percent=\"" << value << "\""
     << " rate=\"" << rate << "\""
     << "/>" << endl;
@@ -182,7 +182,7 @@ void OutXML::dwnldProgress(const zypp::Url & uri,
 void OutXML::dwnldProgressEnd(const zypp::Url & uri, long rate, bool error)
 {
   cout << "<download"
-    << " url=\"" << xml_encode(uri.asString()) << "\""
+    << " url=\"" << xml::escape(uri.asString()) << "\""
     << " rate=\"" << rate << "\""
     << " done=\"" << error << "\""
     << "/>" << endl;
@@ -236,7 +236,7 @@ void OutXML::searchResult( const Table & table_r )
        }
        else
        {
-         cout << xml_encode(*cit) << '"';
+         cout << xml::escape(*cit) << '"';
        }
        ++cidx;
       }
@@ -256,8 +256,8 @@ void OutXML::prompt(PromptId id,
 {
   cout << "<prompt id=\"" << id << "\">" << endl;
   if (!startdesc.empty())
-    cout << "<description>" << xml_encode(startdesc) << "</description>" << endl;
-  cout << "<text>" << xml_encode(prompt) << "</text>" << endl;
+    cout << "<description>" << xml::escape(startdesc) << "</description>" << endl;
+  cout << "<text>" << xml::escape(prompt) << "</text>" << endl;
 
   unsigned int i = 0;
   for (PromptOptions::StrVector::const_iterator it = poptions.options().begin();
@@ -269,8 +269,8 @@ void OutXML::prompt(PromptId id,
     cout << "<option";
     if (poptions.defaultOpt() == i)
       cout << " default=\"1\"";
-    cout << " value=\"" << xml_encode(option) << "\"";
-    cout << " desc=\"" << xml_encode(poptions.optionHelp(i)) << "\"";
+    cout << " value=\"" << xml::escape(option) << "\"";
+    cout << " desc=\"" << xml::escape(poptions.optionHelp(i)) << "\"";
     cout << "/>" << endl;
   }
   cout << "</prompt>" << endl;
index a4ac2ca..3851da5 100644 (file)
@@ -7,7 +7,6 @@
 
 #include <iostream>
 #include <fstream>
-#include <boost/format.hpp>
 #include <boost/logic/tribool.hpp>
 #include <boost/lexical_cast.hpp>
 #include <iterator>
@@ -30,7 +29,7 @@
 #include "getopt.h"
 #include "Table.h"
 #include "utils/messages.h"
-#include "utils/misc.h" // for xml_encode
+#include "utils/misc.h"
 #include "repos.h"
 
 using namespace std;
index d7ae926..f6123c8 100755 (executable)
@@ -148,14 +148,14 @@ static bool xml_list_patches (Zypper & zypper)
         cout << "interactive=\"" << (patch->interactiveWhenIgnoring(ignoreFlags) ? "true" : "false") << "\" ";
         cout << "kind=\"patch\"";
         cout << ">" << endl;
-        cout << "  <summary>" << xml_encode(patch->summary()) << "  </summary>" << endl;
-        cout << "  <description>" << xml_encode(patch->description()) << "</description>" << endl;
-        cout << "  <license>" << xml_encode(patch->licenseToConfirm()) << "</license>" << endl;
+        cout << "  <summary>" << xml::escape(patch->summary()) << "  </summary>" << endl;
+        cout << "  <description>" << xml::escape(patch->description()) << "</description>" << endl;
+        cout << "  <license>" << xml::escape(patch->licenseToConfirm()) << "</license>" << endl;
 
         if ( !patch->repoInfo().alias().empty() )
         {
-          cout << "  <source url=\"" << xml_encode(patch->repoInfo().url().asString());
-          cout << "\" alias=\"" << xml_encode(patch->repoInfo().alias()) << "\"/>" << endl;
+          cout << "  <source url=\"" << xml::escape(patch->repoInfo().url().asString());
+          cout << "\" alias=\"" << xml::escape(patch->repoInfo().alias()) << "\"/>" << endl;
         }
 
         cout << " </update>" << endl;
@@ -187,14 +187,14 @@ static void xml_list_updates(const ResKindSet & kinds)
     cout << "arch=\""  << res->arch().asString() << "\" ";
     cout << "kind=\"" << res->kind() << "\" ";
     cout << ">" << endl;
-    cout << "  <summary>" << xml_encode(res->summary()) << "  </summary>" << endl;
-    cout << "  <description>" << xml_encode(res->description()) << "</description>" << endl;
-    cout << "  <license>" << xml_encode(res->licenseToConfirm()) << "</license>" << endl;
+    cout << "  <summary>" << xml::escape(res->summary()) << "  </summary>" << endl;
+    cout << "  <description>" << xml::escape(res->description()) << "</description>" << endl;
+    cout << "  <license>" << xml::escape(res->licenseToConfirm()) << "</license>" << endl;
 
     if ( !res->repoInfo().alias().empty() )
     {
-        cout << "  <source url=\"" << xml_encode(res->repoInfo().url().asString());
-        cout << "\" alias=\"" << xml_encode(res->repoInfo().alias()) << "\"/>" << endl;
+        cout << "  <source url=\"" << xml::escape(res->repoInfo().url().asString());
+        cout << "\" alias=\"" << xml::escape(res->repoInfo().alias()) << "\"/>" << endl;
     }
 
     cout << " </update>" << endl;
index ec3d1dc..0b7ca83 100644 (file)
@@ -14,7 +14,6 @@
 #include <zypp/base/Easy.h>
 #include <zypp/base/Regex.h>
 #include <zypp/media/MediaManager.h>
-#include <zypp/parser/xml/XmlEscape.h>
 #include <zypp/misc/CheckAccessDeleted.h>
 #include <zypp/ExternalProgram.h>
 
@@ -318,11 +317,6 @@ Pathname cache_rpm(const string & rpm_uri_str, const string & cache_dir)
   return Pathname();
 }
 
-string xml_encode(const string & text)
-{
-  return zypp::xml::escape(text);
-}
-
 std::string & indent(std::string & text, int columns)
 {
   string indent(columns, ' '); indent.insert(0, 1, '\n');
@@ -341,19 +335,19 @@ string asXML(const Product & p, bool is_installed)
   ostringstream str;
   str
     << "<product"
-       " name=\"" << xml_encode(p.name()) << "\""
+       " name=\"" << xml::escape(p.name()) << "\""
        " version=\"" << p.edition().version() << "\""
        " release=\"" << p.edition().release() << "\""
        " epoch=\"" << p.edition().epoch() << "\""
        " arch=\"" << p.arch() << "\""
        " productline=\"" << p.productLine() << "\""
-       " registerrelease=\"" << xml_encode(p.registerRelease()) << "\""
-       " vendor=\"" << xml_encode(p.vendor()) << "\""
-       " summary=\"" << xml_encode(p.summary()) << "\""
-       " shortname=\"" << xml_encode(p.shortName()) << "\""
-       " flavor=\"" << xml_encode(p.flavor()) << "\""
+       " registerrelease=\"" << xml::escape(p.registerRelease()) << "\""
+       " vendor=\"" << xml::escape(p.vendor()) << "\""
+       " summary=\"" << xml::escape(p.summary()) << "\""
+       " shortname=\"" << xml::escape(p.shortName()) << "\""
+       " flavor=\"" << xml::escape(p.flavor()) << "\""
        " isbase=\"" << (p.isTargetDistribution() ? 1 : 0) << "\""
-       " repo=\"" << xml_encode(p.repoInfo().alias()) << "\""
+       " repo=\"" << xml::escape(p.repoInfo().alias()) << "\""
        " installed=\"" << (is_installed ? 1 : 0) << "\"";
   if (p.description().empty())
     str << "/>";
@@ -369,14 +363,14 @@ string asXML(const Pattern & p, bool is_installed)
   ostringstream str;
   str
     << "<pattern"
-       " name=\"" << xml_encode(p.name()) << "\""
+       " name=\"" << xml::escape(p.name()) << "\""
        " version=\"" << p.edition().version() << "\""
        " release=\"" << p.edition().release() << "\""
        " epoch=\"" << p.edition().epoch() << "\""
        " arch=\"" << p.arch() << "\""
-       " vendor=\"" << xml_encode(p.vendor()) << "\""
-       " summary=\"" << xml_encode(p.summary()) << "\""
-       " repo=\"" << xml_encode(p.repoInfo().alias()) << "\""
+       " vendor=\"" << xml::escape(p.vendor()) << "\""
+       " summary=\"" << xml::escape(p.summary()) << "\""
+       " repo=\"" << xml::escape(p.repoInfo().alias()) << "\""
        " installed=\"" << (is_installed ? 1 : 0) << "\""
        " uservisible=\"" << (p.userVisible() ? 1 : 0) << "\"";
   if (p.description().empty())
index af5ed1c..faa8672 100644 (file)
@@ -28,7 +28,7 @@ namespace zypp
   class Product;
   class Pattern;
 }
-
+using namespace zypp;
 
 typedef std::set<zypp::ResKind> ResKindSet;
 
@@ -85,8 +85,6 @@ bool looks_like_rpm_file(const std::string & s);
 zypp::Pathname cache_rpm(const std::string & rpm_uri_str,
                          const std::string & cache_dir);
 
-std::string xml_encode(const std::string & text);
-
 std::string & indent(std::string & text, int columns);
 
 // comparator for RepoInfo set