1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #if ! defined INCLUDED_DP_UPDATE_HXX
29 #define INCLUDED_DP_UPDATE_HXX
30 
31 
32 #include "com/sun/star/deployment/XPackage.hpp"
33 #include "com/sun/star/deployment/XExtensionManager.hpp"
34 #include "com/sun/star/deployment/XUpdateInformationProvider.hpp"
35 #include "com/sun/star/uno/XComponentContext.hpp"
36 #include "com/sun/star/xml/dom/XNode.hpp"
37 
38 #include "rtl/ustrbuf.hxx"
39 #include "dp_misc_api.hxx"
40 
41 #include <map>
42 #include <vector>
43 
44 namespace dp_misc {
45 
46 /** returns the default update URL (for the update information) which
47     is used when an extension does not provide its own URL.
48 */
49 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
50 ::rtl::OUString getExtensionDefaultUpdateURL();
51 
52 enum UPDATE_SOURCE
53 {
54     UPDATE_SOURCE_NONE,
55     UPDATE_SOURCE_SHARED,
56     UPDATE_SOURCE_BUNDLED,
57     UPDATE_SOURCE_ONLINE
58 };
59 
60 /* determine if an update is available which is installed in the
61    user repository.
62 
63    If the return value is UPDATE_SOURCE_NONE, then no update is
64    available, otherwise the return value determine from which the
65    repository the update is used.
66 */
67 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
68 UPDATE_SOURCE isUpdateUserExtension(
69     bool bReadOnlyShared,
70     ::rtl::OUString const & userVersion,
71     ::rtl::OUString const & sharedVersion,
72     ::rtl::OUString const & bundledVersion,
73     ::rtl::OUString const & onlineVersion);
74 
75 /* determine if an update is available which is installed in the
76    shared repository.
77 
78    If the return value is UPDATE_SOURCE_NONE, then no update is
79    available, otherwise the return value determine from which the
80    repository the update is used.
81 */
82 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
83 UPDATE_SOURCE isUpdateSharedExtension(
84     bool bReadOnlyShared,
85     ::rtl::OUString const & sharedVersion,
86     ::rtl::OUString const & bundledVersion,
87     ::rtl::OUString const & onlineVersion);
88 
89 /* determines the extension with the highest identifier and returns it
90 
91  */
92 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
93 ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage>
94 getExtensionWithHighestVersion(
95     ::com::sun::star::uno::Sequence<
96     ::com::sun::star::uno::Reference<
97     ::com::sun::star::deployment::XPackage> > const & seqExtensionsWithSameId);
98 
99 
100 struct UpdateInfo
101 {
102     UpdateInfo( ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage> const & ext);
103     ::com::sun::star::uno::Reference<
104         ::com::sun::star::deployment::XPackage> extension;
105 //version of the update
106     ::rtl::OUString version;
107     ::com::sun::star::uno::Reference< ::com::sun::star::xml::dom::XNode > info;
108 };
109 
110 typedef std::map< ::rtl::OUString, UpdateInfo > UpdateInfoMap;
111 
112 /*
113   @param extensionList
114   List of extension for which online update information are to be obtained. If NULL, then
115   for update information are obtained for all installed extension. There may be only one extension
116   with a particular identifier contained in the list. If one extension is installed
117   in several repositories, then the one with the highest version must be used, because it contains
118   the more recent URLs for getting the update information (if at all).
119   @param out_errors
120   the first member of the pair is the extension  and the second the exception that was produced
121   when processing the extension.
122 
123   @return
124   A map of UpdateInfo instances. If the parameter extensionList was given, then the map contains
125   at only information for those extensions.
126  */
127 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
128 UpdateInfoMap getOnlineUpdateInfos(
129     ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext> const &xContext,
130     ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XExtensionManager> const & xExtMgr,
131     ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XUpdateInformationProvider > const & updateInformation,
132     std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > > const * extensionList,
133     ::std::vector< ::std::pair< ::com::sun::star::uno::Reference<
134     ::com::sun::star::deployment::XPackage>, ::com::sun::star::uno::Any> > & out_errors);
135 
136 /* retunrs the highest version from the provided arguments.
137 */
138 DESKTOP_DEPLOYMENTMISC_DLLPUBLIC
139 ::rtl::OUString getHighestVersion(
140     ::rtl::OUString const & userVersion,
141     ::rtl::OUString const & sharedVersion,
142     ::rtl::OUString const & bundledVersion,
143     ::rtl::OUString const & onlineVersion);
144 
145 }
146 
147 #endif
148