Mailinglist Archive: zypp-commit (171 mails)

< Previous Next >
[zypp-commit] <libzypp> SuSE-SLE-10-SP3-Branch : Support hexencoded modalias strings (bnc #456695, bnc #515858)
  • From: Michael Andres <ma@xxxxxxx>
  • Date: Wed, 24 Jun 2009 12:27:02 +0200
  • Message-id: <E1MJPio-0008GU-3U@xxxxxxxxxxxxxxxx>
ref: refs/heads/SuSE-SLE-10-SP3-Branch
commit b114a8eaa2f7e5adb7b9c6cb20414f0a685d1c0f
Author: Michael Andres <ma@xxxxxxx>
Date: Wed Jun 24 12:27:02 2009 +0200

Support hexencoded modalias strings (bnc #456695, bnc #515858)
---
zypp/base/String.cc | 86 ++++++++++++++++++++++++++++++++++++---
zypp/base/String.h | 16 +++++++-
zypp/capability/ModaliasCap.cc | 3 +-
3 files changed, 96 insertions(+), 9 deletions(-)

diff --git a/zypp/base/String.cc b/zypp/base/String.cc
index 6a2d85a..9a3a29d 100644
--- a/zypp/base/String.cc
+++ b/zypp/base/String.cc
@@ -80,7 +80,79 @@ namespace zypp
);
}

- /******************************************************************
+ ///////////////////////////////////////////////////////////////////
+ // Hexencode
+ ///////////////////////////////////////////////////////////////////
+ namespace {
+ /** What's not decoded. */
+ inline bool heIsAlNum( char ch )
+ {
+ return ( ( 'a' <= ch && ch <= 'z' )
+ ||( 'A' <= ch && ch <= 'Z' )
+ ||( '0' <= ch && ch <= '9' ) );
+ }
+ /** Hex-digit to number or -1. */
+ inline int heDecodeCh( char ch )
+ {
+ if ( '0' <= ch && ch <= '9' )
+ return( ch - '0' );
+ if ( 'A' <= ch && ch <= 'F' )
+ return( ch - 'A' + 10 );
+ if ( 'a' <= ch && ch <= 'f' )
+ return( ch - 'A' + 10 );
+ return -1;
+ }
+ }
+
+ std::string hexencode( const std::string & str_r )
+ {
+ static const char *const hdig = "0123456789ABCDEF";
+ std::string res;
+ res.reserve( str_r.size() );
+ for ( const char * it = str_r.c_str(); *it; ++it )
+ {
+ if ( heIsAlNum( *it ) )
+ {
+ res += *it;
+ }
+ else
+ {
+ res += '%';
+ res += hdig[(unsigned char)(*it)/16];
+ res += hdig[(unsigned char)(*it)%16];
+ }
+ }
+ return res;
+ }
+
+ std::string hexdecode( const std::string & str_r )
+ {
+ std::string res;
+ res.reserve( str_r.size() );
+ for ( const char * it = str_r.c_str(); *it; ++it )
+ {
+ if ( *it == '%' )
+ {
+ int d1 = heDecodeCh( *(it+1) );
+ if ( d1 != -1 )
+ {
+ int d2 = heDecodeCh( *(it+2) );
+ if ( d2 != -1 )
+ {
+ res += (d1<<4)|d2;
+ it += 2;
+ continue;
+ }
+ }
+ }
+ // verbatim if no %XX:
+ res += *it;
+ }
+ return res;
+ }
+ ///////////////////////////////////////////////////////////////////
+
+ /******************************************************************
**
** FUNCTION NAME : toLower
** FUNCTION TYPE : std::string
@@ -161,13 +233,13 @@ namespace zypp
{
if ( ltrim_first )
line = ltrim( line );
-
+
if ( line.empty() )
return line;
-
+
std::string ret;
std::string::size_type p = line.find_first_of( " \t" );
-
+
if ( p == std::string::npos ) {
// no ws on line
ret = line;
@@ -204,15 +276,15 @@ namespace zypp
str.getline( tmpBuff, tmpBuffLen ); // always writes '\0' terminated
ret += tmpBuff;
} while( str.rdstate() == std::ios::failbit );
-
+
return trim( ret, trim_r );
}
-
+
std::string getline( std::istream & str, const Trim trim_r )
{
return _getline(str, trim_r);
}
-
+
std::string getline( std::istream & str, bool trim )
{
return _getline(str, trim?TRIM:NO_TRIM);
diff --git a/zypp/base/String.h b/zypp/base/String.h
index 6f0c672..b8f50a5 100644
--- a/zypp/base/String.h
+++ b/zypp/base/String.h
@@ -207,7 +207,7 @@ namespace zypp

///////////////////////////////////////////////////////////////////
/** Parsing boolean from string.
- */
+ */
//@{
/** Return \c true if str is <tt>1, true, yes, on</tt>. */
bool strToTrue( const std::string & str );
@@ -354,6 +354,20 @@ namespace zypp
{ return join( cont_r.begin(), cont_r.end(), sep_r ); }
//@}

+ ///////////////////////////////////////////////////////////////////
+ /** \name Hexencode.
+ * Encode all characters other than [a-zA-Z0-9] as %XX.
+ * This includes the % character itself, which becomes %25.
+ */
+ //@{
+ /** Encode all characters other than [a-zA-Z0-9] as %XX.
+ * This includes the % character itself, which becomes %25.
+ */
+ std::string hexencode( const std::string & str_r );
+ /** Decode hexencoded %XX sequences. */
+ std::string hexdecode( const std::string & str_r );
+ //@}
+ ///////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////
/** \name Case conversion. */
diff --git a/zypp/capability/ModaliasCap.cc b/zypp/capability/ModaliasCap.cc
index 8e76e63..754c6b7 100644
--- a/zypp/capability/ModaliasCap.cc
+++ b/zypp/capability/ModaliasCap.cc
@@ -11,6 +11,7 @@
*/
#include <iostream>
#include "zypp/base/Logger.h"
+#include "zypp/base/String.h"

#include "zypp/capability/ModaliasCap.h"
#include "zypp/target/modalias/Modalias.h"
@@ -113,7 +114,7 @@ namespace zypp

bool ModaliasCap::evaluate() const
{
- return target::modalias::Modalias::instance().query( _name, _op, _value
);
+ return target::modalias::Modalias::instance().query(
str::hexdecode(_name), _op, _value );
}

/////////////////////////////////////////////////////////////////
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages