1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_desktop.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include "dp_update.hxx"
33*cdf0e10cSrcweir #include "dp_version.hxx"
34*cdf0e10cSrcweir #include "dp_identifier.hxx"
35*cdf0e10cSrcweir #include "dp_descriptioninfoset.hxx"
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir #include "rtl/bootstrap.hxx"
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir using namespace ::com::sun::star;
40*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
41*cdf0e10cSrcweir using ::rtl::OUString;
42*cdf0e10cSrcweir using ::rtl::OString;
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir namespace dp_misc {
46*cdf0e10cSrcweir namespace {
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir int determineHighestVersion(
49*cdf0e10cSrcweir     ::rtl::OUString const & userVersion,
50*cdf0e10cSrcweir     ::rtl::OUString const & sharedVersion,
51*cdf0e10cSrcweir     ::rtl::OUString const & bundledVersion,
52*cdf0e10cSrcweir     ::rtl::OUString const & onlineVersion)
53*cdf0e10cSrcweir {
54*cdf0e10cSrcweir     int index = 0;
55*cdf0e10cSrcweir     OUString  greatest = userVersion;
56*cdf0e10cSrcweir     if (dp_misc::compareVersions(sharedVersion, greatest) == dp_misc::GREATER)
57*cdf0e10cSrcweir     {
58*cdf0e10cSrcweir         index = 1;
59*cdf0e10cSrcweir         greatest = sharedVersion;
60*cdf0e10cSrcweir     }
61*cdf0e10cSrcweir     if (dp_misc::compareVersions(bundledVersion, greatest) == dp_misc::GREATER)
62*cdf0e10cSrcweir     {
63*cdf0e10cSrcweir         index = 2;
64*cdf0e10cSrcweir         greatest = bundledVersion;
65*cdf0e10cSrcweir     }
66*cdf0e10cSrcweir     if (dp_misc::compareVersions(onlineVersion, greatest) == dp_misc::GREATER)
67*cdf0e10cSrcweir     {
68*cdf0e10cSrcweir         index = 3;
69*cdf0e10cSrcweir     }
70*cdf0e10cSrcweir     return index;
71*cdf0e10cSrcweir }
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir Sequence< Reference< xml::dom::XElement > >
74*cdf0e10cSrcweir getUpdateInformation( Reference<deployment::XUpdateInformationProvider > const & updateInformation,
75*cdf0e10cSrcweir                       Sequence< OUString > const & urls,
76*cdf0e10cSrcweir                       OUString const & identifier,
77*cdf0e10cSrcweir                       uno::Any & out_error)
78*cdf0e10cSrcweir {
79*cdf0e10cSrcweir     try {
80*cdf0e10cSrcweir         return updateInformation->getUpdateInformation(urls, identifier);
81*cdf0e10cSrcweir     } catch (uno::RuntimeException &) {
82*cdf0e10cSrcweir         throw;
83*cdf0e10cSrcweir     } catch (ucb::CommandFailedException & e) {
84*cdf0e10cSrcweir         out_error = e.Reason;
85*cdf0e10cSrcweir     } catch (ucb::CommandAbortedException &) {
86*cdf0e10cSrcweir     } catch (uno::Exception & e) {
87*cdf0e10cSrcweir         out_error = uno::makeAny(e);
88*cdf0e10cSrcweir     }
89*cdf0e10cSrcweir     return
90*cdf0e10cSrcweir         Sequence<Reference< xml::dom::XElement > >();
91*cdf0e10cSrcweir }
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir void getOwnUpdateInfos(
94*cdf0e10cSrcweir         Reference<uno::XComponentContext> const & xContext,
95*cdf0e10cSrcweir         Reference<deployment::XUpdateInformationProvider > const &  updateInformation,
96*cdf0e10cSrcweir         UpdateInfoMap& inout_map, std::vector<std::pair<Reference<deployment::XPackage>, uno::Any> > & out_errors,
97*cdf0e10cSrcweir         bool & out_allFound)
98*cdf0e10cSrcweir {
99*cdf0e10cSrcweir     bool allHaveOwnUpdateInformation = true;
100*cdf0e10cSrcweir     for (UpdateInfoMap::iterator i = inout_map.begin(); i != inout_map.end(); i++)
101*cdf0e10cSrcweir     {
102*cdf0e10cSrcweir         OSL_ASSERT(i->second.extension.is());
103*cdf0e10cSrcweir         Sequence<OUString> urls(i->second.extension->getUpdateInformationURLs());
104*cdf0e10cSrcweir         if (urls.getLength())
105*cdf0e10cSrcweir         {
106*cdf0e10cSrcweir             const OUString id =  dp_misc::getIdentifier(i->second.extension);
107*cdf0e10cSrcweir             uno::Any anyError;
108*cdf0e10cSrcweir             //It is unclear from the idl if there can be a null reference returned.
109*cdf0e10cSrcweir             //However all valid information should be the same
110*cdf0e10cSrcweir             Sequence<Reference< xml::dom::XElement > >
111*cdf0e10cSrcweir                 infos(getUpdateInformation(updateInformation, urls, id, anyError));
112*cdf0e10cSrcweir             if (anyError.hasValue())
113*cdf0e10cSrcweir                 out_errors.push_back(std::make_pair(i->second.extension, anyError));
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir             for (sal_Int32 j = 0; j < infos.getLength(); ++j)
116*cdf0e10cSrcweir             {
117*cdf0e10cSrcweir                 dp_misc::DescriptionInfoset infoset(
118*cdf0e10cSrcweir                     xContext,
119*cdf0e10cSrcweir                     Reference< xml::dom::XNode >(infos[j], UNO_QUERY_THROW));
120*cdf0e10cSrcweir                 if (!infoset.hasDescription())
121*cdf0e10cSrcweir                     continue;
122*cdf0e10cSrcweir                 boost::optional< OUString > id2(infoset.getIdentifier());
123*cdf0e10cSrcweir                 if (!id2)
124*cdf0e10cSrcweir                     continue;
125*cdf0e10cSrcweir                 OSL_ASSERT(*id2 == id);
126*cdf0e10cSrcweir                 if (*id2 == id)
127*cdf0e10cSrcweir                 {
128*cdf0e10cSrcweir                     i->second.version = infoset.getVersion();
129*cdf0e10cSrcweir                     i->second.info = Reference< xml::dom::XNode >(
130*cdf0e10cSrcweir                         infos[j], UNO_QUERY_THROW);
131*cdf0e10cSrcweir                 }
132*cdf0e10cSrcweir                 break;
133*cdf0e10cSrcweir             }
134*cdf0e10cSrcweir         }
135*cdf0e10cSrcweir         else
136*cdf0e10cSrcweir         {
137*cdf0e10cSrcweir             allHaveOwnUpdateInformation &= false;
138*cdf0e10cSrcweir         }
139*cdf0e10cSrcweir     }
140*cdf0e10cSrcweir     out_allFound = allHaveOwnUpdateInformation;
141*cdf0e10cSrcweir }
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir void getDefaultUpdateInfos(
144*cdf0e10cSrcweir     Reference<uno::XComponentContext> const & xContext,
145*cdf0e10cSrcweir     Reference<deployment::XUpdateInformationProvider > const &  updateInformation,
146*cdf0e10cSrcweir     UpdateInfoMap& inout_map,
147*cdf0e10cSrcweir      std::vector<std::pair<Reference<deployment::XPackage>, uno::Any> > & out_errors)
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir     const rtl::OUString sDefaultURL(dp_misc::getExtensionDefaultUpdateURL());
150*cdf0e10cSrcweir     OSL_ASSERT(sDefaultURL.getLength());
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir     Any anyError;
153*cdf0e10cSrcweir     Sequence< Reference< xml::dom::XElement > >
154*cdf0e10cSrcweir         infos(
155*cdf0e10cSrcweir             getUpdateInformation(
156*cdf0e10cSrcweir                 updateInformation,
157*cdf0e10cSrcweir                 Sequence< OUString >(&sDefaultURL, 1), OUString(), anyError));
158*cdf0e10cSrcweir     if (anyError.hasValue())
159*cdf0e10cSrcweir         out_errors.push_back(std::make_pair(Reference<deployment::XPackage>(), anyError));
160*cdf0e10cSrcweir     for (sal_Int32 i = 0; i < infos.getLength(); ++i)
161*cdf0e10cSrcweir     {
162*cdf0e10cSrcweir         Reference< xml::dom::XNode > node(infos[i], UNO_QUERY_THROW);
163*cdf0e10cSrcweir         dp_misc::DescriptionInfoset infoset(xContext, node);
164*cdf0e10cSrcweir         boost::optional< OUString > id(infoset.getIdentifier());
165*cdf0e10cSrcweir         if (!id) {
166*cdf0e10cSrcweir             continue;
167*cdf0e10cSrcweir         }
168*cdf0e10cSrcweir         UpdateInfoMap::iterator j = inout_map.find(*id);
169*cdf0e10cSrcweir         if (j != inout_map.end())
170*cdf0e10cSrcweir         {
171*cdf0e10cSrcweir             //skip those extension which provide its own update urls
172*cdf0e10cSrcweir             if (j->second.extension->getUpdateInformationURLs().getLength())
173*cdf0e10cSrcweir                 continue;
174*cdf0e10cSrcweir             OUString v(infoset.getVersion());
175*cdf0e10cSrcweir             //look for the highest version in the online repository
176*cdf0e10cSrcweir             if (dp_misc::compareVersions(v, j->second.version) ==
177*cdf0e10cSrcweir                 dp_misc::GREATER)
178*cdf0e10cSrcweir             {
179*cdf0e10cSrcweir                 j->second.version = v;
180*cdf0e10cSrcweir                 j->second.info = node;
181*cdf0e10cSrcweir             }
182*cdf0e10cSrcweir         }
183*cdf0e10cSrcweir     }
184*cdf0e10cSrcweir }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir bool containsBundledOnly(Sequence<Reference<deployment::XPackage> > const & sameIdExtensions)
187*cdf0e10cSrcweir {
188*cdf0e10cSrcweir     OSL_ASSERT(sameIdExtensions.getLength() == 3);
189*cdf0e10cSrcweir     if (!sameIdExtensions[0].is() && !sameIdExtensions[1].is() && sameIdExtensions[2].is())
190*cdf0e10cSrcweir         return true;
191*cdf0e10cSrcweir     else
192*cdf0e10cSrcweir         return false;
193*cdf0e10cSrcweir }
194*cdf0e10cSrcweir /** Returns true if the list of extensions are bundled extensions and there are no
195*cdf0e10cSrcweir     other extensions with the same identifier in the shared or user repository.
196*cdf0e10cSrcweir     If extensionList is NULL, then it is checked if there are only bundled extensions.
197*cdf0e10cSrcweir */
198*cdf0e10cSrcweir bool onlyBundledExtensions(
199*cdf0e10cSrcweir     Reference<deployment::XExtensionManager> const & xExtMgr,
200*cdf0e10cSrcweir     std::vector< Reference<deployment::XPackage > > const * extensionList)
201*cdf0e10cSrcweir {
202*cdf0e10cSrcweir     OSL_ASSERT(xExtMgr.is());
203*cdf0e10cSrcweir     bool onlyBundled = true;
204*cdf0e10cSrcweir     if (extensionList)
205*cdf0e10cSrcweir     {
206*cdf0e10cSrcweir         typedef std::vector<Reference<deployment::XPackage > >::const_iterator CIT;
207*cdf0e10cSrcweir         for (CIT i = extensionList->begin(); i != extensionList->end(); i++)
208*cdf0e10cSrcweir         {
209*cdf0e10cSrcweir             Sequence<Reference<deployment::XPackage> > seqExt = xExtMgr->getExtensionsWithSameIdentifier(
210*cdf0e10cSrcweir                 dp_misc::getIdentifier(*i), (*i)->getName(), Reference<ucb::XCommandEnvironment>());
211*cdf0e10cSrcweir 
212*cdf0e10cSrcweir             if (!containsBundledOnly(seqExt))
213*cdf0e10cSrcweir             {
214*cdf0e10cSrcweir                 onlyBundled = false;
215*cdf0e10cSrcweir                 break;
216*cdf0e10cSrcweir             }
217*cdf0e10cSrcweir 
218*cdf0e10cSrcweir         }
219*cdf0e10cSrcweir     }
220*cdf0e10cSrcweir     else
221*cdf0e10cSrcweir     {
222*cdf0e10cSrcweir         const uno::Sequence< uno::Sequence< Reference<deployment::XPackage > > > seqAllExt =
223*cdf0e10cSrcweir             xExtMgr->getAllExtensions(Reference<task::XAbortChannel>(), Reference<ucb::XCommandEnvironment>());
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir         for (int pos = seqAllExt.getLength(); pos --; )
226*cdf0e10cSrcweir         {
227*cdf0e10cSrcweir             if (!containsBundledOnly(seqAllExt[pos]))
228*cdf0e10cSrcweir             {
229*cdf0e10cSrcweir                 onlyBundled = false;
230*cdf0e10cSrcweir                 break;
231*cdf0e10cSrcweir             }
232*cdf0e10cSrcweir         }
233*cdf0e10cSrcweir     }
234*cdf0e10cSrcweir     return onlyBundled;
235*cdf0e10cSrcweir }
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir } // anon namespace
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir 
240*cdf0e10cSrcweir OUString getExtensionDefaultUpdateURL()
241*cdf0e10cSrcweir {
242*cdf0e10cSrcweir     ::rtl::OUString sUrl(
243*cdf0e10cSrcweir         RTL_CONSTASCII_USTRINGPARAM(
244*cdf0e10cSrcweir         "${$BRAND_BASE_DIR/program/" SAL_CONFIGFILE("version")
245*cdf0e10cSrcweir         ":Version:ExtensionUpdateURL}"));
246*cdf0e10cSrcweir     ::rtl::Bootstrap::expandMacros(sUrl);
247*cdf0e10cSrcweir     return sUrl;
248*cdf0e10cSrcweir }
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir /* returns the index of the greatest version, starting with 0
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir  */
253*cdf0e10cSrcweir UPDATE_SOURCE isUpdateUserExtension(
254*cdf0e10cSrcweir     bool bReadOnlyShared,
255*cdf0e10cSrcweir     ::rtl::OUString const & userVersion,
256*cdf0e10cSrcweir     ::rtl::OUString const & sharedVersion,
257*cdf0e10cSrcweir     ::rtl::OUString const & bundledVersion,
258*cdf0e10cSrcweir     ::rtl::OUString const & onlineVersion)
259*cdf0e10cSrcweir {
260*cdf0e10cSrcweir     UPDATE_SOURCE retVal = UPDATE_SOURCE_NONE;
261*cdf0e10cSrcweir     if (bReadOnlyShared)
262*cdf0e10cSrcweir     {
263*cdf0e10cSrcweir         if (userVersion.getLength())
264*cdf0e10cSrcweir         {
265*cdf0e10cSrcweir             int index = determineHighestVersion(
266*cdf0e10cSrcweir                 userVersion, sharedVersion, bundledVersion, onlineVersion);
267*cdf0e10cSrcweir             if (index == 1)
268*cdf0e10cSrcweir                 retVal = UPDATE_SOURCE_SHARED;
269*cdf0e10cSrcweir             else if (index == 2)
270*cdf0e10cSrcweir                 retVal = UPDATE_SOURCE_BUNDLED;
271*cdf0e10cSrcweir             else if (index == 3)
272*cdf0e10cSrcweir                 retVal = UPDATE_SOURCE_ONLINE;
273*cdf0e10cSrcweir         }
274*cdf0e10cSrcweir         else if (sharedVersion.getLength())
275*cdf0e10cSrcweir         {
276*cdf0e10cSrcweir             int index = determineHighestVersion(
277*cdf0e10cSrcweir                 OUString(), sharedVersion, bundledVersion, onlineVersion);
278*cdf0e10cSrcweir             if (index == 2)
279*cdf0e10cSrcweir                 retVal = UPDATE_SOURCE_BUNDLED;
280*cdf0e10cSrcweir             else if (index == 3)
281*cdf0e10cSrcweir                 retVal = UPDATE_SOURCE_ONLINE;
282*cdf0e10cSrcweir 
283*cdf0e10cSrcweir         }
284*cdf0e10cSrcweir         //No update for bundled extensions, they are updated only by the setup
285*cdf0e10cSrcweir         //else if (bundledVersion.getLength())
286*cdf0e10cSrcweir         //{
287*cdf0e10cSrcweir         //    int index = determineHighestVersion(
288*cdf0e10cSrcweir         //        OUString(), OUString(), bundledVersion, onlineVersion);
289*cdf0e10cSrcweir         //    if (index == 3)
290*cdf0e10cSrcweir         //        retVal = UPDATE_SOURCE_ONLINE;
291*cdf0e10cSrcweir         //}
292*cdf0e10cSrcweir     }
293*cdf0e10cSrcweir     else
294*cdf0e10cSrcweir     {
295*cdf0e10cSrcweir         if (userVersion.getLength())
296*cdf0e10cSrcweir         {
297*cdf0e10cSrcweir             int index = determineHighestVersion(
298*cdf0e10cSrcweir                 userVersion, sharedVersion, bundledVersion, onlineVersion);
299*cdf0e10cSrcweir             if (index == 1)
300*cdf0e10cSrcweir                 retVal = UPDATE_SOURCE_SHARED;
301*cdf0e10cSrcweir             else if (index == 2)
302*cdf0e10cSrcweir                 retVal = UPDATE_SOURCE_BUNDLED;
303*cdf0e10cSrcweir             else if (index == 3)
304*cdf0e10cSrcweir                 retVal = UPDATE_SOURCE_ONLINE;
305*cdf0e10cSrcweir         }
306*cdf0e10cSrcweir     }
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir     return retVal;
309*cdf0e10cSrcweir }
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir UPDATE_SOURCE isUpdateSharedExtension(
312*cdf0e10cSrcweir     bool bReadOnlyShared,
313*cdf0e10cSrcweir     ::rtl::OUString const & sharedVersion,
314*cdf0e10cSrcweir     ::rtl::OUString const & bundledVersion,
315*cdf0e10cSrcweir     ::rtl::OUString const & onlineVersion)
316*cdf0e10cSrcweir {
317*cdf0e10cSrcweir     if (bReadOnlyShared)
318*cdf0e10cSrcweir         return UPDATE_SOURCE_NONE;
319*cdf0e10cSrcweir     UPDATE_SOURCE retVal = UPDATE_SOURCE_NONE;
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir     if (sharedVersion.getLength())
322*cdf0e10cSrcweir     {
323*cdf0e10cSrcweir         int index = determineHighestVersion(
324*cdf0e10cSrcweir             OUString(), sharedVersion, bundledVersion, onlineVersion);
325*cdf0e10cSrcweir         if (index == 2)
326*cdf0e10cSrcweir             retVal = UPDATE_SOURCE_BUNDLED;
327*cdf0e10cSrcweir         else if (index == 3)
328*cdf0e10cSrcweir             retVal = UPDATE_SOURCE_ONLINE;
329*cdf0e10cSrcweir     }
330*cdf0e10cSrcweir     //No update for bundled extensions, they are updated only by the setup
331*cdf0e10cSrcweir     //else if (bundledVersion.getLength())
332*cdf0e10cSrcweir     //{
333*cdf0e10cSrcweir     //    int index = determineHighestVersion(
334*cdf0e10cSrcweir     //        OUString(), OUString(), bundledVersion, onlineVersion);
335*cdf0e10cSrcweir     //    if (index == 3)
336*cdf0e10cSrcweir     //        retVal = UPDATE_SOURCE_ONLINE;
337*cdf0e10cSrcweir     //}
338*cdf0e10cSrcweir     return retVal;
339*cdf0e10cSrcweir }
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir Reference<deployment::XPackage>
342*cdf0e10cSrcweir getExtensionWithHighestVersion(
343*cdf0e10cSrcweir     Sequence<Reference<deployment::XPackage> > const & seqExt)
344*cdf0e10cSrcweir {
345*cdf0e10cSrcweir     if (seqExt.getLength() == 0)
346*cdf0e10cSrcweir         return Reference<deployment::XPackage>();
347*cdf0e10cSrcweir 
348*cdf0e10cSrcweir     Reference<deployment::XPackage> greatest;
349*cdf0e10cSrcweir     sal_Int32 len = seqExt.getLength();
350*cdf0e10cSrcweir 
351*cdf0e10cSrcweir     for (sal_Int32 i = 0; i < len; i++)
352*cdf0e10cSrcweir     {
353*cdf0e10cSrcweir         if (!greatest.is())
354*cdf0e10cSrcweir         {
355*cdf0e10cSrcweir             greatest = seqExt[i];
356*cdf0e10cSrcweir             continue;
357*cdf0e10cSrcweir         }
358*cdf0e10cSrcweir         Reference<deployment::XPackage> const & current = seqExt[i];
359*cdf0e10cSrcweir         //greatest has a value
360*cdf0e10cSrcweir         if (! current.is())
361*cdf0e10cSrcweir             continue;
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir         if (dp_misc::compareVersions(current->getVersion(), greatest->getVersion()) == dp_misc::GREATER)
364*cdf0e10cSrcweir             greatest = current;
365*cdf0e10cSrcweir     }
366*cdf0e10cSrcweir     return greatest;
367*cdf0e10cSrcweir }
368*cdf0e10cSrcweir 
369*cdf0e10cSrcweir UpdateInfo::UpdateInfo( Reference< deployment::XPackage> const & ext):
370*cdf0e10cSrcweir extension(ext)
371*cdf0e10cSrcweir {
372*cdf0e10cSrcweir }
373*cdf0e10cSrcweir 
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir 
376*cdf0e10cSrcweir UpdateInfoMap getOnlineUpdateInfos(
377*cdf0e10cSrcweir     Reference<uno::XComponentContext> const &xContext,
378*cdf0e10cSrcweir     Reference<deployment::XExtensionManager> const & xExtMgr,
379*cdf0e10cSrcweir     Reference<deployment::XUpdateInformationProvider > const & updateInformation,
380*cdf0e10cSrcweir     std::vector<Reference<deployment::XPackage > > const * extensionList,
381*cdf0e10cSrcweir     std::vector<std::pair< Reference<deployment::XPackage>, uno::Any> > & out_errors)
382*cdf0e10cSrcweir {
383*cdf0e10cSrcweir     OSL_ASSERT(xExtMgr.is());
384*cdf0e10cSrcweir     UpdateInfoMap infoMap;
385*cdf0e10cSrcweir     if (!xExtMgr.is() || onlyBundledExtensions(xExtMgr, extensionList))
386*cdf0e10cSrcweir         return infoMap;
387*cdf0e10cSrcweir 
388*cdf0e10cSrcweir     if (!extensionList)
389*cdf0e10cSrcweir     {
390*cdf0e10cSrcweir         const uno::Sequence< uno::Sequence< Reference<deployment::XPackage > > > seqAllExt =  xExtMgr->getAllExtensions(
391*cdf0e10cSrcweir             Reference<task::XAbortChannel>(), Reference<ucb::XCommandEnvironment>());
392*cdf0e10cSrcweir 
393*cdf0e10cSrcweir         //fill the UpdateInfoMap. key = extension identifier, value = UpdateInfo
394*cdf0e10cSrcweir         for (int pos = seqAllExt.getLength(); pos --; )
395*cdf0e10cSrcweir         {
396*cdf0e10cSrcweir             uno::Sequence<Reference<deployment::XPackage> > const &   seqExt = seqAllExt[pos];
397*cdf0e10cSrcweir 
398*cdf0e10cSrcweir             Reference<deployment::XPackage> extension = getExtensionWithHighestVersion(seqExt);
399*cdf0e10cSrcweir             OSL_ASSERT(extension.is());
400*cdf0e10cSrcweir 
401*cdf0e10cSrcweir             std::pair<UpdateInfoMap::iterator, bool> insertRet = infoMap.insert(
402*cdf0e10cSrcweir                 UpdateInfoMap::value_type(
403*cdf0e10cSrcweir                     dp_misc::getIdentifier(extension), UpdateInfo(extension)));
404*cdf0e10cSrcweir             OSL_ASSERT(insertRet.second == true);
405*cdf0e10cSrcweir         }
406*cdf0e10cSrcweir     }
407*cdf0e10cSrcweir     else
408*cdf0e10cSrcweir     {
409*cdf0e10cSrcweir         typedef std::vector<Reference<deployment::XPackage > >::const_iterator CIT;
410*cdf0e10cSrcweir         for (CIT i = extensionList->begin(); i != extensionList->end(); i++)
411*cdf0e10cSrcweir         {
412*cdf0e10cSrcweir             OSL_ASSERT(i->is());
413*cdf0e10cSrcweir             std::pair<UpdateInfoMap::iterator, bool> insertRet = infoMap.insert(
414*cdf0e10cSrcweir                 UpdateInfoMap::value_type(
415*cdf0e10cSrcweir                     dp_misc::getIdentifier(*i), UpdateInfo(*i)));
416*cdf0e10cSrcweir             OSL_ASSERT(insertRet.second == true);
417*cdf0e10cSrcweir         }
418*cdf0e10cSrcweir     }
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir     //Now find the update information for the extensions which provide their own
421*cdf0e10cSrcweir     //URLs to update information.
422*cdf0e10cSrcweir     bool allInfosObtained = false;
423*cdf0e10cSrcweir     getOwnUpdateInfos(xContext, updateInformation, infoMap, out_errors, allInfosObtained);
424*cdf0e10cSrcweir 
425*cdf0e10cSrcweir     if (!allInfosObtained)
426*cdf0e10cSrcweir         getDefaultUpdateInfos(xContext, updateInformation, infoMap, out_errors);
427*cdf0e10cSrcweir     return infoMap;
428*cdf0e10cSrcweir }
429*cdf0e10cSrcweir OUString getHighestVersion(
430*cdf0e10cSrcweir     ::rtl::OUString const & userVersion,
431*cdf0e10cSrcweir     ::rtl::OUString const & sharedVersion,
432*cdf0e10cSrcweir     ::rtl::OUString const & bundledVersion,
433*cdf0e10cSrcweir     ::rtl::OUString const & onlineVersion)
434*cdf0e10cSrcweir {
435*cdf0e10cSrcweir     int index = determineHighestVersion(userVersion, sharedVersion, bundledVersion, onlineVersion);
436*cdf0e10cSrcweir     switch (index)
437*cdf0e10cSrcweir     {
438*cdf0e10cSrcweir     case 0: return userVersion;
439*cdf0e10cSrcweir     case 1: return sharedVersion;
440*cdf0e10cSrcweir     case 2: return bundledVersion;
441*cdf0e10cSrcweir     case 3: return onlineVersion;
442*cdf0e10cSrcweir     default: OSL_ASSERT(0);
443*cdf0e10cSrcweir     }
444*cdf0e10cSrcweir 
445*cdf0e10cSrcweir     return OUString();
446*cdf0e10cSrcweir }
447*cdf0e10cSrcweir } //namespace dp_misc
448