Commits

Caolán McNamara  committed 0cb6ed6

cmcfixes79: #i114551#: add hyperlink hash calculation

  • Participants
  • Parent commits 277e10f

Comments (0)

Files changed (4)

File filter/inc/filter/msfilter/docinf.hxx

 } } }
 
 
-struct VtHyperlink
+struct MSFILTER_DLLPUBLIC VtHyperlink
 {
     sal_uInt32 dwHash;
     sal_uInt32 dwApp;
     rtl::OUString hlink2;
 
     VtHyperlink() : dwHash(0), dwApp(0), dwOfficeArt(0), dwInfo(0) {}
+    bool hasValidHash() const;
 };
 
 const sal_uInt32 VT_EMPTY           = 0;

File filter/qa/cppunit/filter/summarystreams/makefile.mk

 
 # --- Settings -----------------------------------------------------
 
-.INCLUDE :  settings.mk
+.INCLUDE : settings.mk
+.INCLUDE : comphelper/version.mk
 
 #building with stlport, but cppunit was not built with stlport
 .IF "$(USE_SYSTEM_STL)"!="YES"
 $(MISC)/$(TARGET)/services.rdb:
 	$(MKDIRHIER) $(@:d)
 	$(RM) $@
-	$(REGCOMP) -register -r $@ -wop -c $(DLLPRE)comphelp$(COMPHLP_MAJOR)$(COMID)$(DLLPOST)
+	$(REGCOMP) -register -r $@ -wop -c $(DLLPRE)$(COMPHLP_TARGET)$(COMPHLP_MAJOR)$(COMID)$(DLLPOST)
 
 test1 .PHONY : $(SHL1TARGETN) $(MISC)/$(TARGET)/services.rdb
 	@echo ----------------------------------------------------------

File filter/qa/cppunit/filter/summarystreams/test_summarystreams.cxx

     VtHyperlink aSaveHyperlink;
     aSaveHyperlink.hlink1 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("http://www.redhat.com/somewhere"));
     aSaveHyperlink.hlink2 = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("#somewhere"));
-    aSaveHyperlink.dwHash = 0x1234;
+    aSaveHyperlink.dwHash = 0x4b0018;
     aSaveHyperlink.dwApp = 0x4567;
     aSaveHyperlink.dwOfficeArt = 0xdead;
     aSaveHyperlink.dwInfo = 0xbeaf;
     CPPUNIT_ASSERT_MESSAGE("HyperLinks missing", aLoadHyperlinks.size() == 1);
 
     CPPUNIT_ASSERT_MESSAGE("HyperLink wrong", aLoadHyperlinks[0] == aSaveHyperlink);
+
+    CPPUNIT_ASSERT_MESSAGE("HyperLink Hash wrong", aLoadHyperlinks[0].hasValidHash());
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(SummarystreamsTest);

File filter/source/msfilter/docinf.cxx

     }
     return uno::Sequence<sal_uInt8>();
 }
+
+namespace
+{
+    //2.4.1 Unicode String to Unsigned Integer Hash
+    sal_uInt32 HashString(const rtl::OUString &rInput)
+    {
+        rtl::OUString inputString = rInput.toAsciiLowerCase();
+        sal_uInt32 dwHash = 0;
+        sal_uInt32 nLen = inputString.getLength();
+        if (nLen > 255)
+            nLen = 255;
+        //Documented algorithm is wrong. Truncate string 
+        //to even value
+        nLen = nLen / 2 * 2;
+        for (sal_uInt32 i = 0; i < nLen; i+=2)
+        {
+            sal_Unicode Char1 = inputString.getStr()[i];
+            sal_Unicode Char2 = inputString.getStr()[i+1];
+            sal_uInt32 dwNext = (Char2 << 16) | Char1;
+            dwHash = dwHash ^ dwNext;
+        }
+        return dwHash;
+    }
+}
+
+bool VtHyperlink::hasValidHash() const
+{
+    //2.4.2 Hyperlink Hash
+    sal_uInt32 dwHash1 = HashString(hlink1);
+    sal_uInt32 dwHash2 = HashString(hlink2);
+    sal_uInt32 calc_dwHash = dwHash1 ^ dwHash2;
+    return calc_dwHash == dwHash;
+}