LCOV - code coverage report
Current view: top level - xmlsecurity/source/dialogs - resourcemanager.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 137 0.0 %
Date: 2012-08-25 Functions: 0 13 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 162 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*
       3                 :            :  * This file is part of the LibreOffice project.
       4                 :            :  *
       5                 :            :  * This Source Code Form is subject to the terms of the Mozilla Public
       6                 :            :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7                 :            :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8                 :            :  *
       9                 :            :  * This file incorporates work covered by the following license notice:
      10                 :            :  *
      11                 :            :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12                 :            :  *   contributor license agreements. See the NOTICE file distributed
      13                 :            :  *   with this work for additional information regarding copyright
      14                 :            :  *   ownership. The ASF licenses this file to you under the Apache
      15                 :            :  *   License, Version 2.0 (the "License"); you may not use this file
      16                 :            :  *   except in compliance with the License. You may obtain a copy of
      17                 :            :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18                 :            :  */
      19                 :            : 
      20                 :            : 
      21                 :            : #include "resourcemanager.hxx"
      22                 :            : 
      23                 :            : #include <vcl/svapp.hxx>
      24                 :            : #include <vcl/fixed.hxx>
      25                 :            : #include <svtools/stdctrl.hxx>
      26                 :            : #include <svl/solar.hrc>
      27                 :            : #include <unotools/syslocale.hxx>
      28                 :            : #include <rtl/ustring.h>
      29                 :            : #include <rtl/ustrbuf.h>
      30                 :            : #include <vector>
      31                 :            : 
      32                 :            : using ::rtl::OUString;
      33                 :            : using namespace std;
      34                 :            : 
      35                 :            : namespace XmlSec
      36                 :            : {
      37                 :            :     static ResMgr*          pResMgr = 0;
      38                 :            :     static SvtSysLocale*    pSysLocale = 0;
      39                 :            : 
      40                 :          0 :     ResMgr* GetResMgr( void )
      41                 :            :     {
      42         [ #  # ]:          0 :         if (!pResMgr)
      43         [ #  # ]:          0 :             pResMgr = ResMgr::CreateResMgr("xmlsec");
      44                 :          0 :         return pResMgr;
      45                 :            :     }
      46                 :            : 
      47                 :          0 :     const LocaleDataWrapper&    GetLocaleData( void )
      48                 :            :     {
      49         [ #  # ]:          0 :         if (!pSysLocale)
      50         [ #  # ]:          0 :             pSysLocale = new SvtSysLocale;
      51                 :          0 :         return pSysLocale->GetLocaleData();
      52                 :            :     }
      53                 :            : 
      54                 :          0 :     DateTime GetDateTime( const ::com::sun::star::util::DateTime& _rDT )
      55                 :            :     {
      56                 :            :         return DateTime(
      57                 :            :             Date( _rDT.Day, _rDT.Month, _rDT.Year ),
      58         [ #  # ]:          0 :             Time( _rDT.Hours, _rDT.Minutes, _rDT.Seconds, _rDT.HundredthSeconds ) );
      59                 :            :     }
      60                 :            : 
      61                 :          0 :     String GetDateTimeString( const ::com::sun::star::util::DateTime& _rDT )
      62                 :            :     {
      63                 :            :         // String with date and time information (#i20172#)
      64         [ #  # ]:          0 :         DateTime aDT( GetDateTime( _rDT ) );
      65         [ #  # ]:          0 :         const LocaleDataWrapper& rLoDa = GetLocaleData();
      66 [ #  # ][ #  # ]:          0 :         String sRet( rLoDa.getDate( aDT ) );
      67         [ #  # ]:          0 :         sRet += ' ';
      68 [ #  # ][ #  # ]:          0 :         sRet += rLoDa.getTime( aDT );
      69                 :          0 :         return sRet;
      70                 :            :     }
      71                 :            : 
      72                 :          0 :     String GetDateString( const ::com::sun::star::util::DateTime& _rDT )
      73                 :            :     {
      74 [ #  # ][ #  # ]:          0 :         return GetLocaleData().getDate( GetDateTime( _rDT ) );
                 [ #  # ]
      75                 :            :     }
      76                 :            : 
      77                 :            :     /*
      78                 :            :         Creates two strings based on the distinguished name which are displayed in the
      79                 :            :         certificate details view. The first string contains only the values of the attribute
      80                 :            :         and valudes pairs, which are separated by commas. All escape characters ('"') are
      81                 :            :         removed.
      82                 :            :         The second string is for the details view at the bottom. It shows the attribute/value
      83                 :            :         pairs on different lines. All escape characters ('"') are removed.
      84                 :            :     */
      85                 :          0 :     pair< OUString, OUString> GetDNForCertDetailsView( const OUString & rRawString)
      86                 :            :     {
      87         [ #  # ]:          0 :         vector< pair< OUString, OUString > > vecAttrValueOfDN = parseDN(rRawString);
      88                 :          0 :         ::rtl::OUStringBuffer s1, s2;
      89         [ #  # ]:          0 :         OUString sEqual(RTL_CONSTASCII_USTRINGPARAM(" = "));
      90                 :            :         typedef vector< pair < OUString, OUString > >::const_iterator CIT;
      91 [ #  # ][ #  # ]:          0 :         for (CIT i = vecAttrValueOfDN.begin(); i < vecAttrValueOfDN.end(); ++i)
                 [ #  # ]
      92                 :            :         {
      93 [ #  # ][ #  # ]:          0 :             if (i != vecAttrValueOfDN.begin())
      94                 :            :             {
      95         [ #  # ]:          0 :                 s1.append(static_cast<sal_Unicode>(','));
      96         [ #  # ]:          0 :                 s2.append(static_cast<sal_Unicode>('\n'));
      97                 :            :             }
      98         [ #  # ]:          0 :             s1.append(i->second);
      99         [ #  # ]:          0 :             s2.append(i->first);
     100         [ #  # ]:          0 :             s2.append(sEqual);
     101         [ #  # ]:          0 :             s2.append(i->second);
     102                 :            :         }
     103 [ #  # ][ #  # ]:          0 :         return make_pair(s1.makeStringAndClear(), s2.makeStringAndClear());
     104                 :            :     }
     105                 :            : 
     106                 :            : /*
     107                 :            :     Whenever the attribute value contains special characters, such as '"' or ',' (without '')
     108                 :            :     then the value will be enclosed in double quotes by the respective Windows or NSS function
     109                 :            :     which we use to retrieve, for example, the subject name. If double quotes appear in the value then
     110                 :            :     they are escaped with a double quote. This function removes the escape characters.
     111                 :            : */
     112                 :            : #ifdef WNT
     113                 :            : vector< pair< OUString, OUString> > parseDN(const OUString& rRawString)
     114                 :            : {
     115                 :            :         vector< pair<OUString, OUString> > retVal;
     116                 :            :         bool bInEscape = false;
     117                 :            :         bool bInValue = false;
     118                 :            :         bool bInType = true;
     119                 :            :         sal_Int32 nTypeNameStart = 0;
     120                 :            :         OUString sType;
     121                 :            :         ::rtl::OUStringBuffer sbufValue;
     122                 :            :         sal_Int32 length = rRawString.getLength();
     123                 :            : 
     124                 :            :         for (sal_Int32 i = 0; i < length; i++)
     125                 :            :         {
     126                 :            :             sal_Unicode c = rRawString[i];
     127                 :            : 
     128                 :            :             if (c == '=')
     129                 :            :             {
     130                 :            :                 if (! bInValue)
     131                 :            :                 {
     132                 :            :                     sType = rRawString.copy(nTypeNameStart, i - nTypeNameStart);
     133                 :            :                     sType = sType.trim();
     134                 :            :                     bInType = false;
     135                 :            :                 }
     136                 :            :                 else
     137                 :            :                 {
     138                 :            :                     sbufValue.append(c);
     139                 :            :                 }
     140                 :            :             }
     141                 :            :             else if (c == '"')
     142                 :            :             {
     143                 :            :                 if (!bInEscape)
     144                 :            :                 {
     145                 :            :                     //If this is the quote is the first of the couple which enclose the
     146                 :            :                     //whole value, because the value contains special characters
     147                 :            :                     //then we just drop it. That is, this character must be followed by
     148                 :            :                     //a character which is not '"'.
     149                 :            :                     if ( i + 1 < length && rRawString[i+1] == '"')
     150                 :            :                         bInEscape = true;
     151                 :            :                     else
     152                 :            :                         bInValue = !bInValue; //value is enclosed in " "
     153                 :            :                 }
     154                 :            :                 else
     155                 :            :                 {
     156                 :            :                     //This quote is escaped by a preceding quote and therefore is
     157                 :            :                     //part of the value
     158                 :            :                     sbufValue.append(c);
     159                 :            :                     bInEscape = false;
     160                 :            :                 }
     161                 :            :             }
     162                 :            :             else if (c == ',' || c == '+')
     163                 :            :             {
     164                 :            :                 //The comma separate the attribute value pairs.
     165                 :            :                 //If the comma is not part of a value (the value would then be enclosed in '"'),
     166                 :            :                 //then we have reached the end of the value
     167                 :            :                 if (!bInValue)
     168                 :            :                 {
     169                 :            :                     OSL_ASSERT(!sType.isEmpty());
     170                 :            :                     retVal.push_back(make_pair(sType, sbufValue.makeStringAndClear()));
     171                 :            :                     sType = OUString();
     172                 :            :                     //The next char is the start of the new type
     173                 :            :                     nTypeNameStart = i + 1;
     174                 :            :                     bInType = true;
     175                 :            :                 }
     176                 :            :                 else
     177                 :            :                 {
     178                 :            :                     //The whole string is enclosed because it contains special characters.
     179                 :            :                     //The enclosing '"' are not part of certificate but will be added by
     180                 :            :                     //the function (Windows or NSS) which retrieves DN
     181                 :            :                     sbufValue.append(c);
     182                 :            :                 }
     183                 :            :             }
     184                 :            :             else
     185                 :            :             {
     186                 :            :                 if (!bInType)
     187                 :            :                     sbufValue.append(c);
     188                 :            :             }
     189                 :            :         }
     190                 :            :         if (sbufValue.getLength())
     191                 :            :         {
     192                 :            :             OSL_ASSERT(!sType.isEmpty());
     193                 :            :             retVal.push_back(make_pair(sType, sbufValue.makeStringAndClear()));
     194                 :            :         }
     195                 :            :         return retVal;
     196                 :            :     }
     197                 :            : #else
     198                 :          0 : vector< pair< OUString, OUString> > parseDN(const OUString& rRawString)
     199                 :            :     {
     200         [ #  # ]:          0 :         vector< pair<OUString, OUString> > retVal;
     201                 :            :         //bInEscape == true means that the preceding character is an escape character
     202                 :          0 :         bool bInEscape = false;
     203                 :          0 :         bool bInValue = false;
     204                 :          0 :         bool bInType = true;
     205                 :          0 :         sal_Int32 nTypeNameStart = 0;
     206                 :          0 :         OUString sType;
     207                 :          0 :         ::rtl::OUStringBuffer sbufValue;
     208                 :          0 :         sal_Int32 length = rRawString.getLength();
     209                 :            : 
     210         [ #  # ]:          0 :         for (sal_Int32 i = 0; i < length; i++)
     211                 :            :         {
     212                 :          0 :             sal_Unicode c = rRawString[i];
     213                 :            : 
     214         [ #  # ]:          0 :             if (c == '=')
     215                 :            :             {
     216         [ #  # ]:          0 :                 if (! bInValue)
     217                 :            :                 {
     218                 :          0 :                     sType = rRawString.copy(nTypeNameStart, i - nTypeNameStart);
     219                 :          0 :                     sType = sType.trim();
     220                 :          0 :                     bInType = false;
     221                 :            :                 }
     222                 :            :                 else
     223                 :            :                 {
     224         [ #  # ]:          0 :                     sbufValue.append(c);
     225                 :            :                 }
     226                 :            :             }
     227         [ #  # ]:          0 :             else if (c == '\\')
     228                 :            :             {
     229         [ #  # ]:          0 :                 if (!bInEscape)
     230                 :            :                 {
     231                 :          0 :                     bInEscape = true;
     232                 :            :                 }
     233                 :            :                 else
     234                 :            :                 { // bInEscape is true
     235         [ #  # ]:          0 :                     sbufValue.append(c);
     236                 :          0 :                     bInEscape = false;
     237                 :            :                 }
     238                 :            :             }
     239         [ #  # ]:          0 :             else if (c == '"')
     240                 :            :             {
     241                 :            :                 //an unescaped '"' is either at the beginning or end of the value
     242         [ #  # ]:          0 :                 if (!bInEscape)
     243                 :            :                 {
     244         [ #  # ]:          0 :                     if ( !bInValue)
     245                 :          0 :                         bInValue = true;
     246         [ #  # ]:          0 :                     else if (bInValue)
     247                 :          0 :                         bInValue = false;
     248                 :            :                 }
     249                 :            :                 else
     250                 :            :                 {
     251                 :            :                     //This quote is escaped by a preceding quote and therefore is
     252                 :            :                     //part of the value
     253         [ #  # ]:          0 :                     sbufValue.append(c);
     254                 :          0 :                     bInEscape = false;
     255                 :            :                 }
     256                 :            :             }
     257 [ #  # ][ #  # ]:          0 :             else if (c == ',' || c == '+')
     258                 :            :             {
     259                 :            :                 //The comma separate the attribute value pairs.
     260                 :            :                 //If the comma is not part of a value (the value would then be enclosed in '"'),
     261                 :            :                 //then we have reached the end of the value
     262         [ #  # ]:          0 :                 if (!bInValue)
     263                 :            :                 {
     264                 :            :                     OSL_ASSERT(!sType.isEmpty());
     265 [ #  # ][ #  # ]:          0 :                     retVal.push_back(make_pair(sType, sbufValue.makeStringAndClear()));
     266                 :          0 :                     sType = OUString();
     267                 :            :                     //The next char is the start of the new type
     268                 :          0 :                     nTypeNameStart = i + 1;
     269                 :          0 :                     bInType = true;
     270                 :            :                 }
     271                 :            :                 else
     272                 :            :                 {
     273                 :            :                     //The whole string is enclosed because it contains special characters.
     274                 :            :                     //The enclosing '"' are not part of certificate but will be added by
     275                 :            :                     //the function (Windows or NSS) which retrieves DN
     276         [ #  # ]:          0 :                     sbufValue.append(c);
     277                 :            :                 }
     278                 :            :             }
     279                 :            :             else
     280                 :            :             {
     281         [ #  # ]:          0 :                 if (!bInType)
     282                 :            :                 {
     283         [ #  # ]:          0 :                     sbufValue.append(c);
     284                 :          0 :                     bInEscape = false;
     285                 :            :                 }
     286                 :            :             }
     287                 :            :         }
     288         [ #  # ]:          0 :         if (sbufValue.getLength())
     289                 :            :         {
     290                 :            :             OSL_ASSERT(!sType.isEmpty());
     291 [ #  # ][ #  # ]:          0 :             retVal.push_back(make_pair(sType, sbufValue.makeStringAndClear()));
     292                 :            :         }
     293                 :          0 :         return retVal;
     294                 :            :     }
     295                 :            : 
     296                 :            : #endif
     297                 :            : 
     298                 :          0 :     String GetContentPart( const String& _rRawString )
     299                 :            :     {
     300                 :          0 :         char const * aIDs[] = { "CN", "OU", "O", "E", NULL };
     301                 :          0 :         OUString retVal;
     302                 :          0 :         int i = 0;
     303 [ #  # ][ #  # ]:          0 :         vector< pair< OUString, OUString > > vecAttrValueOfDN = parseDN(_rRawString);
     304         [ #  # ]:          0 :         while ( aIDs[i] )
     305                 :            :         {
     306                 :          0 :             OUString sPartId = OUString::createFromAscii( aIDs[i++] );
     307                 :            :             typedef vector< pair < OUString, OUString > >::const_iterator CIT;
     308 [ #  # ][ #  # ]:          0 :             for (CIT idn = vecAttrValueOfDN.begin(); idn != vecAttrValueOfDN.end(); ++idn)
                 [ #  # ]
     309                 :            :             {
     310         [ #  # ]:          0 :                 if (idn->first.equals(sPartId))
     311                 :            :                 {
     312                 :          0 :                     retVal = idn->second;
     313                 :          0 :                     break;
     314                 :            :                 }
     315                 :            :             }
     316         [ #  # ]:          0 :             if (!retVal.isEmpty())
     317                 :            :                 break;
     318         [ #  # ]:          0 :         }
     319         [ #  # ]:          0 :         return retVal;
     320                 :            :     }
     321                 :            : 
     322                 :          0 :     String GetHexString( const ::com::sun::star::uno::Sequence< sal_Int8 >& _rSeq, const char* _pSep, sal_uInt16 _nLineBreak )
     323                 :            :     {
     324                 :          0 :         const sal_Int8*         pSerNumSeq = _rSeq.getConstArray();
     325                 :          0 :         int                     nCnt = _rSeq.getLength();
     326         [ #  # ]:          0 :         String                  aStr;
     327                 :          0 :         const char              pHexDigs[ 17 ] = "0123456789ABCDEF";
     328                 :          0 :         char                    pBuffer[ 3 ] = "  ";
     329                 :            :         sal_uInt8                   nNum;
     330         [ #  # ]:          0 :         sal_uInt16                  nBreakStart = _nLineBreak? _nLineBreak : 1;
     331                 :          0 :         sal_uInt16                  nBreak = nBreakStart;
     332         [ #  # ]:          0 :         for( int i = 0 ; i < nCnt ; ++i )
     333                 :            :         {
     334                 :          0 :             nNum = sal_uInt8( pSerNumSeq[ i ] );
     335                 :            : 
     336                 :            :             // exchange the buffer[0] and buffer[1], which make it consistent with Mozilla and Windows
     337                 :          0 :             pBuffer[ 1 ] = pHexDigs[ nNum & 0x0F ];
     338                 :          0 :             nNum >>= 4;
     339                 :          0 :             pBuffer[ 0 ] = pHexDigs[ nNum ];
     340         [ #  # ]:          0 :             aStr.AppendAscii( pBuffer );
     341                 :            : 
     342                 :          0 :             --nBreak;
     343         [ #  # ]:          0 :             if( nBreak )
     344         [ #  # ]:          0 :                 aStr.AppendAscii( _pSep );
     345                 :            :             else
     346                 :            :             {
     347                 :          0 :                 nBreak = nBreakStart;
     348         [ #  # ]:          0 :                 aStr.AppendAscii( "\n" );
     349                 :            :             }
     350                 :            :         }
     351                 :            : 
     352                 :          0 :         return aStr;
     353                 :            :     }
     354                 :            : 
     355                 :          0 :     long ShrinkToFitWidth( Control& _rCtrl, long _nOffs )
     356                 :            :     {
     357 [ #  # ][ #  # ]:          0 :         long    nWidth = _rCtrl.GetTextWidth( _rCtrl.GetText() );
                 [ #  # ]
     358         [ #  # ]:          0 :         Size    aSize( _rCtrl.GetSizePixel() );
     359                 :          0 :         nWidth += _nOffs;
     360                 :          0 :         aSize.Width() = nWidth;
     361         [ #  # ]:          0 :         _rCtrl.SetSizePixel( aSize );
     362                 :          0 :         return nWidth;
     363                 :            :     }
     364                 :            : 
     365                 :          0 :     void AlignAfterImage( const FixedImage& _rImage, Control& _rCtrl, long _nXOffset )
     366                 :            :     {
     367         [ #  # ]:          0 :         Point   aPos( _rImage.GetPosPixel() );
     368         [ #  # ]:          0 :         Size    aSize( _rImage.GetSizePixel() );
     369                 :          0 :         long    n = aPos.X();
     370                 :          0 :         n += aSize.Width();
     371                 :          0 :         n += _nXOffset;
     372                 :          0 :         aPos.X() = n;
     373                 :          0 :         n = aPos.Y();
     374                 :          0 :         n += aSize.Height() / 2;                    // y-position is in the middle of the image
     375         [ #  # ]:          0 :         n -= _rCtrl.GetSizePixel().Height() / 2;    // center Control
     376                 :          0 :         aPos.Y() = n;
     377         [ #  # ]:          0 :         _rCtrl.SetPosPixel( aPos );
     378                 :          0 :     }
     379                 :            : 
     380                 :          0 :     void AlignAfterImage( const FixedImage& _rImage, FixedInfo& _rFI, long _nXOffset )
     381                 :            :     {
     382                 :          0 :         AlignAfterImage( _rImage, static_cast< Control& >( _rFI ), _nXOffset );
     383                 :          0 :         ShrinkToFitWidth( _rFI );
     384                 :          0 :     }
     385                 :            : 
     386                 :          0 :     void AlignAndFitImageAndControl( FixedImage& _rImage, FixedInfo& _rFI, long _nXOffset )
     387                 :            :     {
     388         [ #  # ]:          0 :         _rImage.SetSizePixel( _rImage.GetImage().GetSizePixel() );
     389                 :          0 :         AlignAfterImage( _rImage, _rFI, _nXOffset );
     390                 :          0 :     }
     391                 :            : }
     392                 :            : 
     393                 :            : 
     394                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10