[shibboleth-sp2] 67/82: SSPCPP-750 use converters to go from string to wstring

Etienne Dysli Metref edm-guest at moszumanska.debian.org
Thu Nov 16 08:16:26 UTC 2017


This is an automated email from the git hooks/post-receive script.

edm-guest pushed a commit to branch master
in repository shibboleth-sp2.

commit a3679ce1454c2a95a0dcdfd223d5dd6b39f57d5e
Author: Rod Widdowson <rdw at steadingsoftware.com>
Date:   Tue Sep 26 11:26:32 2017 +0100

    SSPCPP-750 use converters to go from string to wstring
    
    https://issues.shibboleth.net/jira/browse/SSPCPP-750
    
    IIS7 needs a lot of PCWSTR parameters but internally we work on std::string.
    Rather than abuse auto_ptr_XMLCh, use the inbuild converters to do the
    work.
---
 iis7_shib/IIS7Request.cpp      | 10 +++++-----
 iis7_shib/ShibUser.cpp         | 11 +++++++----
 iis7_shib/headers/ShibUser.hpp |  2 +-
 iis7_shib/register.cpp         | 15 +++++++++------
 4 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/iis7_shib/IIS7Request.cpp b/iis7_shib/IIS7Request.cpp
index 6fab59b..bb53f6e 100644
--- a/iis7_shib/IIS7Request.cpp
+++ b/iis7_shib/IIS7Request.cpp
@@ -157,19 +157,19 @@ void IIS7Request::setHeader(const char* name, const char* value)
         }
     }
     if (m_useVariables) {
-        const auto_ptr_XMLCh widen(value); // TODO : use a converter?
-        const HRESULT hr(m_ctx->SetServerVariable(const_cast<char*>(name), reinterpret_cast<PCWSTR>(widen.get())));
+        std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
+        const wstring wValue(converter.from_bytes(value));
+        const HRESULT hr(m_ctx->SetServerVariable(const_cast<char*>(name), wValue.c_str()));
         if (FAILED(hr)) {
             throwError("setHeader (Variable)", hr);
         }
 
         for (vector<string>::iterator roleAttribute = g_RoleAttributeNames.begin(); roleAttribute != g_RoleAttributeNames.end(); ++roleAttribute) {
             if (*roleAttribute == name) {
-                string str(value);
+                const string str(value);
                 tokenizer<escaped_list_separator<char>> tok(str, escaped_list_separator<char>('\\', ';', '"'));
                 for (tokenizer<escaped_list_separator<char>>::iterator it = tok.begin(); it != tok.end(); ++it) {
-                    const xmltooling::auto_ptr_XMLCh widen(it->c_str());
-                    m_roles.insert(reinterpret_cast<PCWSTR>(widen.get()));
+                    m_roles.insert(converter.from_bytes(*it));
                 }
             }
         }
diff --git a/iis7_shib/ShibUser.cpp b/iis7_shib/ShibUser.cpp
index ff1a57b..783784a 100644
--- a/iis7_shib/ShibUser.cpp
+++ b/iis7_shib/ShibUser.cpp
@@ -20,22 +20,25 @@
 
 #include "IIS7_shib.hpp"
 #include "ShibUser.hpp"
+#include <codecvt> // 16 bit to 8 bit and vice versa chars
 
-ShibUser::ShibUser(std::string name, set<wstring> roles) : m_refCount(1), m_widen(name.c_str()), m_roles(roles)
+
+ShibUser::ShibUser(std::string name, set<wstring> roles) : m_refCount(1), m_roles(roles)
 {
-    ;
+    std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
+    m_username = converter.from_bytes(string(name));
 }
 
 PCWSTR
 ShibUser::GetRemoteUserName(VOID)
 {
-    return reinterpret_cast<PCWSTR>(m_widen.get());
+    return m_username.c_str();
 }
 
 PCWSTR
 ShibUser::GetUserName(VOID)
 {
-    return reinterpret_cast<PCWSTR>(m_widen.get());
+    return m_username.c_str();
 }
 
 PCWSTR
diff --git a/iis7_shib/headers/ShibUser.hpp b/iis7_shib/headers/ShibUser.hpp
index e550b60..09c8258 100644
--- a/iis7_shib/headers/ShibUser.hpp
+++ b/iis7_shib/headers/ShibUser.hpp
@@ -85,7 +85,7 @@ public:
     );
 
 private:
-    const auto_ptr_XMLCh m_widen;
+    wstring m_username;
     volatile unsigned int m_refCount;
     const set<wstring> m_roles;
 };
\ No newline at end of file
diff --git a/iis7_shib/register.cpp b/iis7_shib/register.cpp
index 3b23de9..babd0c7 100644
--- a/iis7_shib/register.cpp
+++ b/iis7_shib/register.cpp
@@ -29,6 +29,7 @@
 #include "../util/RegistrySignature.h"
 #include <xmltooling/logging.h>
 #pragma warning(disable: 4996)
+#include <codecvt> // 16 bit to 8 bit and vice versa chars
 #include <boost/algorithm/string.hpp>
 
 
@@ -45,7 +46,7 @@ namespace Config {
     bool g_bUseVariables = true;
     vector<string> g_NoCerts;
     vector<string> g_RoleAttributeNames;
-    wstring g_authNRole;
+    wstring g_authNRole(L"ShibbolethAuthN");
 }
 
 using namespace Config;
@@ -191,16 +192,18 @@ RegisterModule(
             const PropertySet* roles = props->getPropertySet("Roles");
             if (roles) {
                 const pair<bool, const char*> authNRoleFlag = roles->getString("authNRole");
-                xmltooling::auto_ptr_XMLCh rolestr(authNRoleFlag.first? authNRoleFlag.second : "ShibbolethAuthN");
-                g_authNRole = reinterpret_cast<PCWSTR>(rolestr.get());
+
+                if (authNRoleFlag.first) {
+                    std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
+                    wstring rolestr(converter.from_bytes(string(authNRoleFlag.second)));
+
+                    g_authNRole = rolestr;
+                }
 
                 const pair<bool, const char*> theRoles = roles->getString("roleAttributes");
                 if (theRoles.first) {
-#pragma warning(disable: 4996)
                     boost::split(g_RoleAttributeNames, theRoles.second, boost::algorithm::is_space(), boost::algorithm::token_compress_on);
                 }
-            } else {
-                g_authNRole = L"ShibbolethAuthN";
             }
         }
     }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-shibboleth/shibboleth-sp2.git



More information about the Pkg-shibboleth-devel mailing list