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 #if ! defined INCLUDED_DP_UPDATE_HXX
25 #define INCLUDED_DP_UPDATE_HXX
26 
27 
28 #include "com/sun/star/deployment/XPackage.hpp"
29 #include "com/sun/star/deployment/XExtensionManager.hpp"
30 #include "com/sun/star/deployment/XUpdateInformationProvider.hpp"
31 #include "com/sun/star/uno/XComponentContext.hpp"
32 #include "com/sun/star/xml/dom/XNode.hpp"
33 
34 #include "rtl/ustrbuf.hxx"
35 #include "dp_misc_api.hxx"
36 
37 #include <map>
38 #include <vector>
39 
40 namespace dp_misc {
41 
42 /** returns the default update URL (for the update information) which
43     is used when an extension does not provide its own URL.
44 */
45 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
46 ::rtl::OUString getExtensionDefaultUpdateURL();
47 
48 enum UPDATE_SOURCE
49 {
50     UPDATE_SOURCE_NONE,
51     UPDATE_SOURCE_SHARED,
52     UPDATE_SOURCE_BUNDLED,
53     UPDATE_SOURCE_ONLINE
54 };
55 
56 /* determine if an update is available which is installed in the
57    user repository.
58 
59    If the return value is UPDATE_SOURCE_NONE, then no update is
60    available, otherwise the return value determine from which the
61    repository the update is used.
62 */
63 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
64 UPDATE_SOURCE isUpdateUserExtension(
65     bool bReadOnlyShared,
66     ::rtl::OUString const & userVersion,
67     ::rtl::OUString const & sharedVersion,
68     ::rtl::OUString const & bundledVersion,
69     ::rtl::OUString const & onlineVersion);
70 
71 /* determine if an update is available which is installed in the
72    shared repository.
73 
74    If the return value is UPDATE_SOURCE_NONE, then no update is
75    available, otherwise the return value determine from which the
76    repository the update is used.
77 */
78 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
79 UPDATE_SOURCE isUpdateSharedExtension(
80     bool bReadOnlyShared,
81     ::rtl::OUString const & sharedVersion,
82     ::rtl::OUString const & bundledVersion,
83     ::rtl::OUString const & onlineVersion);
84 
85 /* determines the extension with the highest identifier and returns it
86 
87  */
88 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
89 ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage>
90 getExtensionWithHighestVersion(
91     ::com::sun::star::uno::Sequence<
92     ::com::sun::star::uno::Reference<
93     ::com::sun::star::deployment::XPackage> > const & seqExtensionsWithSameId);
94 
95 
96 struct UpdateInfo
97 {
98     UpdateInfo( ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage> const & ext);
99     ::com::sun::star::uno::Reference<
100         ::com::sun::star::deployment::XPackage> extension;
101 //version of the update
102     ::rtl::OUString version;
103     ::com::sun::star::uno::Reference< ::com::sun::star::xml::dom::XNode > info;
104 };
105 
106 typedef std::map< ::rtl::OUString, UpdateInfo > UpdateInfoMap;
107 
108 /*
109   @param extensionList
110   List of extension for which online update information are to be obtained. If NULL, then
111   for update information are obtained for all installed extension. There may be only one extension
112   with a particular identifier contained in the list. If one extension is installed
113   in several repositories, then the one with the highest version must be used, because it contains
114   the more recent URLs for getting the update information (if at all).
115   @param out_errors
116   the first member of the pair is the extension  and the second the exception that was produced
117   when processing the extension.
118 
119   @return
120   A map of UpdateInfo instances. If the parameter extensionList was given, then the map contains
121   at only information for those extensions.
122  */
123 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
124 UpdateInfoMap getOnlineUpdateInfos(
125     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext> const &xContext,
126     ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XExtensionManager> const & xExtMgr,
127     ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XUpdateInformationProvider > const & updateInformation,
128     std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > > const * extensionList,
129     ::std::vector< ::std::pair< ::com::sun::star::uno::Reference<
130     ::com::sun::star::deployment::XPackage>, ::com::sun::star::uno::Any> > & out_errors);
131 
132 /* retunrs the highest version from the provided arguments.
133 */
134 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
135 ::rtl::OUString getHighestVersion(
136     ::rtl::OUString const & userVersion,
137     ::rtl::OUString const & sharedVersion,
138     ::rtl::OUString const & bundledVersion,
139     ::rtl::OUString const & onlineVersion);
140 
141 }
142 
143 #endif
144