1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _MANIFEST_IMPORT_HXX
25 #define _MANIFEST_IMPORT_HXX
26 
27 #include <cppuhelper/implbase1.hxx> // helper for implementations
28 #ifndef _COM_SUN_STAR_XML_SAX_XDUCUMENTHANDLER_HPP_
29 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
30 #endif
31 #include <vector>
32 
33 #include <HashMaps.hxx>
34 
35 namespace com { namespace sun { namespace star {
36 	namespace xml { namespace sax { class XAttributeList; } }
37 	namespace beans { struct PropertyValue; }
38 } } }
39 
40 typedef ::std::hash_map< ::rtl::OUString, ::rtl::OUString, ::rtl::OUStringHash, eqFunc > StringHashMap;
41 
42 struct ManifestScopeEntry
43 {
44     ::rtl::OUString m_aConvertedName;
45     StringHashMap   m_aNamespaces;
46 
47     ManifestScopeEntry( const ::rtl::OUString& aConvertedName, const StringHashMap& aNamespaces )
48     : m_aConvertedName( aConvertedName )
49     , m_aNamespaces( aNamespaces )
50     {}
51 
52     ~ManifestScopeEntry()
53     {}
54 };
55 
56 typedef ::std::vector< ManifestScopeEntry > ManifestStack;
57 
58 class ManifestImport : public cppu::WeakImplHelper1 < com::sun::star::xml::sax::XDocumentHandler >
59 {
60 protected:
61 	com::sun::star::uno::Sequence < com::sun::star::beans::PropertyValue > aSequence;
62 	sal_Int16 		nNumProperty;
63 	ManifestStack aStack;
64 	sal_Bool bIgnoreEncryptData;
65     sal_Int32 nDerivedKeySize;
66 	::std::vector < ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue > > & rManVector;
67 
68 	const ::rtl::OUString sFileEntryElement;
69 	const ::rtl::OUString sManifestElement;
70 	const ::rtl::OUString sEncryptionDataElement;
71 	const ::rtl::OUString sAlgorithmElement;
72 	const ::rtl::OUString sStartKeyAlgElement;
73 	const ::rtl::OUString sKeyDerivationElement;
74 
75 	const ::rtl::OUString sCdataAttribute;
76 	const ::rtl::OUString sMediaTypeAttribute;
77 	const ::rtl::OUString sVersionAttribute;
78 	const ::rtl::OUString sFullPathAttribute;
79 	const ::rtl::OUString sSizeAttribute;
80 	const ::rtl::OUString sSaltAttribute;
81 	const ::rtl::OUString sInitialisationVectorAttribute;
82 	const ::rtl::OUString sIterationCountAttribute;
83 	const ::rtl::OUString sKeySizeAttribute;
84 	const ::rtl::OUString sAlgorithmNameAttribute;
85 	const ::rtl::OUString sStartKeyAlgNameAttribute;
86 	const ::rtl::OUString sKeyDerivationNameAttribute;
87 	const ::rtl::OUString sChecksumAttribute;
88 	const ::rtl::OUString sChecksumTypeAttribute;
89 
90 	const ::rtl::OUString sFullPathProperty;
91 	const ::rtl::OUString sMediaTypeProperty;
92 	const ::rtl::OUString sVersionProperty;
93 	const ::rtl::OUString sIterationCountProperty;
94 	const ::rtl::OUString sDerivedKeySizeProperty;
95 	const ::rtl::OUString sSaltProperty;
96 	const ::rtl::OUString sInitialisationVectorProperty;
97 	const ::rtl::OUString sSizeProperty;
98 	const ::rtl::OUString sDigestProperty;
99     const ::rtl::OUString sEncryptionAlgProperty;
100     const ::rtl::OUString sStartKeyAlgProperty;
101     const ::rtl::OUString sDigestAlgProperty;
102 
103 	const ::rtl::OUString sWhiteSpace;
104 
105 	const ::rtl::OUString sSHA256_URL;
106 	const ::rtl::OUString sSHA1_Name;
107 	const ::rtl::OUString sSHA1_URL;
108 
109 	const ::rtl::OUString sSHA256_1k_URL;
110 	const ::rtl::OUString sSHA1_1k_Name;
111 	const ::rtl::OUString sSHA1_1k_URL;
112 
113 	const ::rtl::OUString sBlowfish_Name;
114 	const ::rtl::OUString sBlowfish_URL;
115 	const ::rtl::OUString sAES128_URL;
116 	const ::rtl::OUString sAES192_URL;
117 	const ::rtl::OUString sAES256_URL;
118 
119 	const ::rtl::OUString sPBKDF2_Name;
120 	const ::rtl::OUString sPBKDF2_URL;
121 
122 
123     ::rtl::OUString PushNameAndNamespaces( const ::rtl::OUString& aName,
124                                            const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttribs,
125                                            StringHashMap& o_aConvertedAttribs );
126     ::rtl::OUString ConvertNameWithNamespace( const ::rtl::OUString& aName, const StringHashMap& aNamespaces );
127     ::rtl::OUString ConvertName( const ::rtl::OUString& aName );
128 
129 public:
130 	ManifestImport( std::vector < ::com::sun::star::uno::Sequence < ::com::sun::star::beans::PropertyValue > > & rNewVector );
131 	~ManifestImport( void );
132     virtual void SAL_CALL startDocument(  )
133 		throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
134     virtual void SAL_CALL endDocument(  )
135 		throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
136     virtual void SAL_CALL startElement( const ::rtl::OUString& aName, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >& xAttribs )
137 		throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
138     virtual void SAL_CALL endElement( const ::rtl::OUString& aName )
139 		throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
140     virtual void SAL_CALL characters( const ::rtl::OUString& aChars )
141 		throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
142     virtual void SAL_CALL ignorableWhitespace( const ::rtl::OUString& aWhitespaces )
143 		throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
144     virtual void SAL_CALL processingInstruction( const ::rtl::OUString& aTarget, const ::rtl::OUString& aData )
145 		throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
146     virtual void SAL_CALL setDocumentLocator( const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >& xLocator )
147 		throw(::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException);
148 };
149 #endif
150