~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/xpinstall/src/nsUpdateNotification.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
2
/*
 
3
 * The contents of this file are subject to the Netscape Public
 
4
 * License Version 1.1 (the "License"); you may not use this file
 
5
 * except in compliance with the License. You may obtain a copy of
 
6
 * the License at http://www.mozilla.org/NPL/
 
7
 *
 
8
 * Software distributed under the License is distributed on an "AS
 
9
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
10
 * implied. See the License for the specific language governing
 
11
 * rights and limitations under the License.
 
12
 *
 
13
 * The Original Code is Mozilla Communicator client code, 
 
14
 * released March 31, 1998. 
 
15
 *
 
16
 * The Initial Developer of the Original Code is Netscape Communications 
 
17
 * Corporation.  Portions created by Netscape are
 
18
 * Copyright (C) 1998-1999 Netscape Communications Corporation. All
 
19
 * Rights Reserved.
 
20
 *
 
21
 * Contributor(s): 
 
22
 *   Doug Turner <dougt@netscape.com>
 
23
 *   Pierre Phaneuf <pp@ludusdesign.com>
 
24
 */
 
25
 
 
26
 
 
27
#include "nsUpdateNotification.h"
 
28
 
 
29
#include "nsISupports.h"
 
30
#include "nsIServiceManager.h"
 
31
#include "nsCOMPtr.h"
 
32
#include "nsIComponentManager.h"
 
33
#include "nsIGenericFactory.h"
 
34
#include "nsIRDFContainer.h"
 
35
#include "nsIRDFDataSource.h"
 
36
#include "nsIRDFService.h"
 
37
#include "nsIRDFRemoteDataSource.h"
 
38
#include "nsRDFCID.h"
 
39
#include "nsIRDFXMLSink.h"
 
40
 
 
41
#include "nsIPrefBranch.h"
 
42
#include "nsIPrefService.h"
 
43
#include "nsISoftwareUpdate.h"
 
44
 
 
45
#define NC_RDF_NAME                     "http://home.netscape.com/NC-rdf#name"
 
46
#define NC_RDF_SOURCE                   "http://home.netscape.com/NC-rdf#source"
 
47
#define NC_RDF_URL                              "http://home.netscape.com/NC-rdf#url"
 
48
#define NC_RDF_CHILD                    "http://home.netscape.com/NC-rdf#child"
 
49
 
 
50
#define NC_RDF_NOTIFICATION_ROOT        "http://home.netscape.com/NC-rdf#SoftwareNotificationRoot"
 
51
#define NC_XPI_SOURCES              "http://home.netscape.com/NC-rdf#SoftwareUpdateDataSources"
 
52
#define NC_XPI_PACKAGES             "http://home.netscape.com/NC-rdf#SoftwarePackages"
 
53
 
 
54
#define NC_XPI_TITLE        "http://home.netscape.com/NC-rdf#title"
 
55
#define NC_XPI_REGKEY       "http://home.netscape.com/NC-rdf#registryKey"
 
56
#define NC_XPI_VERSION      "http://home.netscape.com/NC-rdf#version"
 
57
#define NC_XPI_DESCRIPTION      "http://home.netscape.com/NC-rdf#description"
 
58
 
 
59
static NS_DEFINE_CID(kRDFServiceCID,   NS_RDFSERVICE_CID);
 
60
static NS_DEFINE_CID(kRDFContainerCID, NS_RDFCONTAINER_CID);
 
61
 
 
62
nsIRDFResource* nsXPINotifierImpl::kXPI_NotifierSources = nsnull;
 
63
nsIRDFResource* nsXPINotifierImpl::kXPI_NotifierPackages = nsnull;
 
64
nsIRDFResource* nsXPINotifierImpl::kXPI_NotifierPackage_Title = nsnull;
 
65
nsIRDFResource* nsXPINotifierImpl::kXPI_NotifierPackage_Version = nsnull;
 
66
nsIRDFResource* nsXPINotifierImpl::kXPI_NotifierPackage_Description = nsnull;
 
67
nsIRDFResource* nsXPINotifierImpl::kXPI_NotifierPackage_RegKey = nsnull;
 
68
 
 
69
nsIRDFResource* nsXPINotifierImpl::kNC_NotificationRoot = nsnull;
 
70
nsIRDFResource* nsXPINotifierImpl::kNC_Source = nsnull;
 
71
nsIRDFResource* nsXPINotifierImpl::kNC_Name = nsnull;
 
72
nsIRDFResource* nsXPINotifierImpl::kNC_URL = nsnull;
 
73
nsIRDFResource* nsXPINotifierImpl::kNC_Child = nsnull;
 
74
 
 
75
 
 
76
nsXPINotifierImpl::nsXPINotifierImpl()
 
77
    : mRDF(nsnull)
 
78
{
 
79
    mPendingRefreshes = 0;
 
80
 
 
81
    static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
 
82
    
 
83
    nsComponentManager::CreateInstance(kRDFInMemoryDataSourceCID,
 
84
                                       nsnull,
 
85
                                       NS_GET_IID(nsISupports),
 
86
                                       getter_AddRefs(mNotifications));
 
87
}
 
88
 
 
89
 
 
90
nsXPINotifierImpl::~nsXPINotifierImpl()
 
91
{
 
92
    if (mRDF) 
 
93
    {
 
94
        nsServiceManager::ReleaseService(kRDFServiceCID, mRDF);
 
95
        mRDF = nsnull;
 
96
    }
 
97
 
 
98
    NS_IF_RELEASE(kXPI_NotifierSources);
 
99
    NS_IF_RELEASE(kXPI_NotifierPackages);
 
100
    NS_IF_RELEASE(kXPI_NotifierPackage_Title);
 
101
    NS_IF_RELEASE(kXPI_NotifierPackage_Version);
 
102
    NS_IF_RELEASE(kXPI_NotifierPackage_Description);
 
103
    NS_IF_RELEASE(kXPI_NotifierPackage_RegKey);
 
104
 
 
105
        NS_IF_RELEASE(kNC_NotificationRoot);
 
106
    NS_IF_RELEASE(kNC_Source);
 
107
        NS_IF_RELEASE(kNC_Name);
 
108
        NS_IF_RELEASE(kNC_URL);
 
109
        NS_IF_RELEASE(kNC_Child);
 
110
}
 
111
 
 
112
 
 
113
NS_IMPL_ISUPPORTS2(nsXPINotifierImpl, nsIRDFXMLSinkObserver, nsIUpdateNotification)
 
114
 
 
115
 
 
116
nsresult
 
117
nsXPINotifierImpl::NotificationEnabled(PRBool* aReturn)
 
118
{
 
119
    *aReturn = PR_FALSE;
 
120
 
 
121
    nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID);
 
122
 
 
123
    if ( prefBranch )
 
124
    {
 
125
        PRBool value;
 
126
        // check to see if we are on.
 
127
        nsresult rv = prefBranch->GetBoolPref( (const char*) XPINSTALL_NOTIFICATIONS_ENABLE, &value);
 
128
 
 
129
        if (NS_SUCCEEDED(rv) && value)
 
130
        {
 
131
            // check to see the last time we did anything.  Since flash does not have a persistant
 
132
            // way to do poll invervals longer than a session, we will implemented that here by using the
 
133
            // preferences.  
 
134
 
 
135
            PRInt32 intervalHours = 0;
 
136
            
 
137
            PRTime now            = 0;
 
138
            PRInt32 nowSec        = 0;
 
139
 
 
140
            PRInt32 lastTime      = 0;
 
141
            
 
142
            rv = prefBranch->GetIntPref(XPINSTALL_NOTIFICATIONS_INTERVAL, &intervalHours);
 
143
 
 
144
            if (NS_FAILED(rv))
 
145
            {
 
146
                intervalHours = 7*24;  // default at once a week
 
147
                rv = prefBranch->SetIntPref(XPINSTALL_NOTIFICATIONS_INTERVAL, intervalHours);
 
148
            }
 
149
 
 
150
            rv = prefBranch->GetIntPref(XPINSTALL_NOTIFICATIONS_LASTDATE, &lastTime);
 
151
    
 
152
            now = PR_Now();
 
153
 
 
154
            // nowSec = now / 1000000
 
155
            LL_DIV(nowSec, now, 1000000);
 
156
 
 
157
            if (NS_FAILED(rv) || lastTime == 0)
 
158
            {
 
159
                rv = prefBranch->SetIntPref(XPINSTALL_NOTIFICATIONS_LASTDATE, nowSec);
 
160
                return NS_OK;
 
161
            }
 
162
            
 
163
            if ((lastTime + (intervalHours*60*24)) <= nowSec)
 
164
            {
 
165
                *aReturn = PR_TRUE;
 
166
            }
 
167
        }
 
168
    }
 
169
    
 
170
    return NS_OK;
 
171
}
 
172
 
 
173
nsresult
 
174
nsXPINotifierImpl::Init()
 
175
{
 
176
    PRBool enabled;
 
177
 
 
178
    NotificationEnabled(&enabled);
 
179
 
 
180
    if (!enabled)
 
181
        return NS_ERROR_FAILURE;
 
182
    
 
183
    if (mNotifications == nsnull)
 
184
        return NS_ERROR_FAILURE;
 
185
 
 
186
    nsresult rv;
 
187
    nsCOMPtr<nsIRDFDataSource> distributors;
 
188
    nsCOMPtr<nsIRDFContainer> distributorsContainer;
 
189
    nsCOMPtr <nsISimpleEnumerator> distributorEnumerator;
 
190
    PRBool moreElements;
 
191
    
 
192
    // Read the distributor registry
 
193
    rv = nsServiceManager::GetService(kRDFServiceCID, NS_GET_IID(nsIRDFService), (nsISupports**) &mRDF);
 
194
    if (NS_FAILED(rv)) return rv;
 
195
    
 
196
    if (! kXPI_NotifierSources)
 
197
        {
 
198
           mRDF->GetResource(NC_XPI_SOURCES,       &kXPI_NotifierSources);
 
199
       mRDF->GetResource(NC_XPI_PACKAGES,      &kXPI_NotifierPackages);
 
200
       mRDF->GetResource(NC_XPI_TITLE,         &kXPI_NotifierPackage_Title);
 
201
       mRDF->GetResource(NC_XPI_VERSION,       &kXPI_NotifierPackage_Version);
 
202
       mRDF->GetResource(NC_XPI_DESCRIPTION,   &kXPI_NotifierPackage_Description);
 
203
       mRDF->GetResource(NC_XPI_REGKEY,        &kXPI_NotifierPackage_RegKey);
 
204
 
 
205
       mRDF->GetResource(NC_RDF_NOTIFICATION_ROOT,  &kNC_NotificationRoot);
 
206
       
 
207
       mRDF->GetResource(NC_RDF_SOURCE,             &kNC_Source);
 
208
           mRDF->GetResource(NC_RDF_NAME,               &kNC_Name);
 
209
           mRDF->GetResource(NC_RDF_URL,                &kNC_URL);
 
210
           mRDF->GetResource(NC_RDF_CHILD,              &kNC_Child);
 
211
 
 
212
        }
 
213
 
 
214
    rv = OpenRemoteDataSource(BASE_DATASOURCE_URL, PR_TRUE, getter_AddRefs(distributors));
 
215
    if (NS_FAILED(rv)) return rv;
 
216
 
 
217
    rv = nsComponentManager::CreateInstance(kRDFContainerCID,
 
218
                                            nsnull,
 
219
                                            NS_GET_IID(nsIRDFContainer),
 
220
                                            getter_AddRefs(distributorsContainer));
 
221
 
 
222
    if (NS_SUCCEEDED(rv))
 
223
    {
 
224
        rv = distributorsContainer->Init(distributors, kXPI_NotifierSources);
 
225
        
 
226
        if (NS_SUCCEEDED(rv))
 
227
        {
 
228
            rv = distributorsContainer->GetElements(getter_AddRefs(distributorEnumerator));
 
229
 
 
230
            if (NS_SUCCEEDED(rv))
 
231
            {
 
232
                distributorEnumerator->HasMoreElements(&moreElements);
 
233
                while (moreElements) 
 
234
                {
 
235
                    nsCOMPtr<nsISupports> i;
 
236
                    rv = distributorEnumerator->GetNext(getter_AddRefs(i));
 
237
                    if (NS_FAILED(rv)) break;
 
238
 
 
239
                    nsCOMPtr<nsIRDFResource> aDistributor(do_QueryInterface(i, &rv));
 
240
                    if (NS_FAILED(rv)) break;
 
241
 
 
242
                    char* uri;
 
243
                    nsCOMPtr<nsIRDFDataSource> remoteDatasource;
 
244
                    aDistributor->GetValue(&uri);
 
245
 
 
246
                    rv = OpenRemoteDataSource(uri, PR_FALSE, getter_AddRefs(remoteDatasource));
 
247
                                        nsMemory::Free(uri);
 
248
                    if (NS_FAILED(rv)) break;
 
249
                    
 
250
                    distributorEnumerator->HasMoreElements(&moreElements);
 
251
                }
 
252
            }
 
253
        }
 
254
    }
 
255
    return NS_OK;
 
256
}
 
257
 
 
258
 
 
259
PRBool 
 
260
nsXPINotifierImpl::IsNewerOrUninstalled(const char* regKey, const char* versionString)
 
261
{
 
262
    PRBool needJar = PR_FALSE;
 
263
 
 
264
    REGERR status = VR_ValidateComponent( (char*) regKey );
 
265
 
 
266
    if ( status == REGERR_NOFIND || status == REGERR_NOFILE )
 
267
    {
 
268
        // either component is not in the registry or it's a file
 
269
        // node and the physical file is missing
 
270
        needJar = PR_TRUE;
 
271
    }
 
272
    else
 
273
    {
 
274
        VERSION oldVersion;
 
275
 
 
276
        status = VR_GetVersion( (char*)regKey, &oldVersion );
 
277
        
 
278
        if ( status != REGERR_OK )
 
279
        {
 
280
            needJar = PR_TRUE;
 
281
        }
 
282
        else 
 
283
        {
 
284
            VERSION newVersion;
 
285
 
 
286
            StringToVersionNumbers(versionString, &(newVersion).major, &(newVersion).minor, &(newVersion).release, &(newVersion).build);
 
287
            
 
288
            if ( CompareVersions(&oldVersion, &newVersion) < 0 )
 
289
                needJar = PR_TRUE;
 
290
        }
 
291
    }
 
292
    return needJar;
 
293
}
 
294
 
 
295
 
 
296
PRInt32
 
297
nsXPINotifierImpl::CompareVersions(VERSION *oldversion, VERSION *newVersion)
 
298
{
 
299
    PRInt32 diff;
 
300
    
 
301
    if ( oldversion->major == newVersion->major ) 
 
302
    {
 
303
        if ( oldversion->minor == newVersion->minor ) 
 
304
        {
 
305
            if ( oldversion->release == newVersion->release ) 
 
306
            {
 
307
                if ( oldversion->build == newVersion->build )
 
308
                    diff = 0;
 
309
                else if ( oldversion->build > newVersion->build )
 
310
                    diff = 1;
 
311
                else
 
312
                    diff = -1;
 
313
            }
 
314
            else if ( oldversion->release > newVersion->release )
 
315
                diff = 1;
 
316
            else
 
317
                diff = -1;
 
318
        }
 
319
        else if (  oldversion->minor > newVersion->minor )
 
320
            diff = 1;
 
321
        else
 
322
            diff = -1;
 
323
    }
 
324
    else if ( oldversion->major > newVersion->major )
 
325
        diff = 1;
 
326
    else
 
327
        diff = -1;
 
328
 
 
329
    return diff;
 
330
}
 
331
 
 
332
 
 
333
void
 
334
nsXPINotifierImpl::StringToVersionNumbers(const nsString& version, int32 *aMajor, int32 *aMinor, int32 *aRelease, int32 *aBuild)    
 
335
{
 
336
    PRInt32 errorCode;
 
337
 
 
338
    int dot = version.FindChar('.', 0);
 
339
    
 
340
    if ( dot == -1 ) 
 
341
    {
 
342
        *aMajor = version.ToInteger(&errorCode);
 
343
    }
 
344
    else  
 
345
    {
 
346
        nsString majorStr;
 
347
        version.Mid(majorStr, 0, dot);
 
348
        *aMajor  = majorStr.ToInteger(&errorCode);
 
349
 
 
350
        int prev = dot+1;
 
351
        dot = version.FindChar('.',prev);
 
352
        if ( dot == -1 ) 
 
353
        {
 
354
            nsString minorStr;
 
355
            version.Mid(minorStr, prev, version.Length() - prev);
 
356
            *aMinor = minorStr.ToInteger(&errorCode);
 
357
        }
 
358
        else 
 
359
        {
 
360
            nsString minorStr;
 
361
            version.Mid(minorStr, prev, dot - prev);
 
362
            *aMinor = minorStr.ToInteger(&errorCode);
 
363
 
 
364
            prev = dot+1;
 
365
            dot = version.FindChar('.',prev);
 
366
            if ( dot == -1 ) 
 
367
            {
 
368
                nsString releaseStr;
 
369
                version.Mid(releaseStr, prev, version.Length() - prev);
 
370
                *aRelease = releaseStr.ToInteger(&errorCode);
 
371
            }
 
372
            else 
 
373
            {
 
374
                nsString releaseStr;
 
375
                version.Mid(releaseStr, prev, dot - prev);
 
376
                *aRelease = releaseStr.ToInteger(&errorCode);
 
377
    
 
378
                prev = dot+1;
 
379
                if ( version.Length() > dot ) 
 
380
                {
 
381
                    nsString buildStr;
 
382
                    version.Mid(buildStr, prev, version.Length() - prev);
 
383
                    *aBuild = buildStr.ToInteger(&errorCode);
 
384
               }
 
385
            }
 
386
        }
 
387
    }
 
388
}
 
389
 
 
390
nsresult
 
391
nsXPINotifierImpl::OpenRemoteDataSource(const char* aURL, PRBool blocking, nsIRDFDataSource** aResult)
 
392
{
 
393
    static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
 
394
    nsresult rv;
 
395
 
 
396
    nsCOMPtr<nsIRDFRemoteDataSource> remote;
 
397
    rv = nsComponentManager::CreateInstance(kRDFXMLDataSourceCID,
 
398
                                            nsnull,
 
399
                                            NS_GET_IID(nsIRDFRemoteDataSource),
 
400
                                            getter_AddRefs(remote));
 
401
    if (NS_FAILED(rv)) return rv;
 
402
 
 
403
    rv = remote->Init(aURL);
 
404
    if (NS_SUCCEEDED(rv)) 
 
405
    {
 
406
        if (! blocking)
 
407
        {
 
408
            nsCOMPtr<nsIRDFXMLSink> sink = do_QueryInterface(remote, &rv);
 
409
            if (NS_FAILED(rv)) return rv;
 
410
 
 
411
            rv = sink->AddXMLSinkObserver(this);
 
412
            if (NS_FAILED(rv)) return rv;
 
413
        }
 
414
 
 
415
        rv = remote->Refresh(blocking);
 
416
        if (NS_FAILED(rv)) return rv;
 
417
 
 
418
        nsCOMPtr<nsIRDFDataSource> result = do_QueryInterface(remote, &rv);
 
419
        *aResult = result;
 
420
        NS_IF_ADDREF(*aResult);
 
421
        return rv;
 
422
    }
 
423
    else 
 
424
    {
 
425
        // we've already loaded this datasource. use cached copy
 
426
        return mRDF->GetDataSource(aURL, aResult);
 
427
    }
 
428
}
 
429
 
 
430
 
 
431
NS_IMETHODIMP
 
432
nsXPINotifierImpl::New(nsISupports* aOuter, REFNSIID aIID, void** aResult)
 
433
{
 
434
    NS_PRECONDITION(aOuter == nsnull, "no aggregation");
 
435
    if (aOuter)
 
436
        return NS_ERROR_NO_AGGREGATION;
 
437
 
 
438
    nsXPINotifierImpl* result = new nsXPINotifierImpl();
 
439
    if (! result)
 
440
        return NS_ERROR_OUT_OF_MEMORY;
 
441
 
 
442
    NS_ADDREF(result); // stabilize
 
443
 
 
444
    nsresult rv;
 
445
    rv = result->Init();
 
446
    if (NS_SUCCEEDED(rv)) {
 
447
        rv = result->QueryInterface(aIID, aResult);
 
448
    }
 
449
 
 
450
    NS_RELEASE(result);
 
451
    return rv;
 
452
}
 
453
 
 
454
 
 
455
NS_IMETHODIMP
 
456
nsXPINotifierImpl::OnBeginLoad(nsIRDFXMLSink *aSink)
 
457
{
 
458
    return NS_OK;
 
459
}
 
460
 
 
461
NS_IMETHODIMP
 
462
nsXPINotifierImpl::OnInterrupt(nsIRDFXMLSink *aSink)
 
463
{
 
464
    return NS_OK;
 
465
}
 
466
NS_IMETHODIMP
 
467
nsXPINotifierImpl::OnResume(nsIRDFXMLSink *aSink)
 
468
{
 
469
    return NS_OK;
 
470
}
 
471
 
 
472
NS_IMETHODIMP
 
473
nsXPINotifierImpl::OnEndLoad(nsIRDFXMLSink *aSink)
 
474
{
 
475
    nsresult rv;
 
476
 
 
477
    (void) aSink->RemoveXMLSinkObserver(this);
 
478
 
 
479
    nsCOMPtr<nsIRDFDataSource> distributorDataSource = do_QueryInterface(aSink, &rv);
 
480
    if (NS_FAILED(rv)) return rv;
 
481
 
 
482
    nsCOMPtr<nsIRDFContainer> distributorContainer;
 
483
    nsCOMPtr <nsISimpleEnumerator> packageEnumerator;
 
484
    PRBool moreElements;
 
485
 
 
486
    rv = nsComponentManager::CreateInstance(kRDFContainerCID,
 
487
                                            nsnull,
 
488
                                            NS_GET_IID(nsIRDFContainer),
 
489
                                            getter_AddRefs(distributorContainer));
 
490
    if (NS_SUCCEEDED(rv))
 
491
    {
 
492
        rv = distributorContainer->Init(distributorDataSource, kXPI_NotifierPackages);
 
493
        if (NS_SUCCEEDED(rv))
 
494
        {
 
495
            rv = distributorContainer->GetElements(getter_AddRefs(packageEnumerator));
 
496
            if (NS_SUCCEEDED(rv))
 
497
            {
 
498
                packageEnumerator->HasMoreElements(&moreElements);
 
499
                while (moreElements) 
 
500
                {
 
501
                    nsCOMPtr<nsISupports> i;
 
502
 
 
503
                    rv = packageEnumerator->GetNext(getter_AddRefs(i));
 
504
                    if (NS_FAILED(rv)) break;
 
505
 
 
506
                    nsCOMPtr<nsIRDFResource> aPackage(do_QueryInterface(i, &rv));
 
507
                    if (NS_FAILED(rv)) break;
 
508
    
 
509
                    
 
510
                    // Get the version information
 
511
                    nsCOMPtr<nsIRDFNode> versionNode;
 
512
                    distributorDataSource->GetTarget(aPackage, 
 
513
                                                     kXPI_NotifierPackage_Version, 
 
514
                                                     PR_TRUE, 
 
515
                                                     getter_AddRefs(versionNode));
 
516
 
 
517
                    nsCOMPtr<nsIRDFLiteral> version(do_QueryInterface(versionNode, &rv));
 
518
                    if (NS_FAILED(rv)) break;
 
519
 
 
520
                    // Get the regkey information
 
521
                    nsCOMPtr<nsIRDFNode> regkeyNode;
 
522
                    distributorDataSource->GetTarget(aPackage, 
 
523
                                                     kXPI_NotifierPackage_RegKey, 
 
524
                                                     PR_TRUE, 
 
525
                                                     getter_AddRefs(regkeyNode));
 
526
 
 
527
                    nsCOMPtr<nsIRDFLiteral> regkey(do_QueryInterface(regkeyNode, &rv));
 
528
                    if (NS_FAILED(rv)) break;
 
529
 
 
530
                    // convert them into workable nsAutoStrings
 
531
                    PRUnichar* regkeyCString;
 
532
                    regkey->GetValue(&regkeyCString);
 
533
                    nsString regKeyString(regkeyCString);
 
534
                    
 
535
                    PRUnichar* versionCString;
 
536
                    version->GetValue(&versionCString);
 
537
                    nsString versionString(versionCString);
 
538
                                        nsMemory::Free(versionCString);
 
539
                                        nsMemory::Free(regkeyCString);
 
540
 
 
541
                    // check to see if this software title should be "flashed"
 
542
                    if (IsNewerOrUninstalled(NS_ConvertUCS2toUTF8(regKeyString).get(), NS_ConvertUCS2toUTF8(versionString).get()))
 
543
                    {
 
544
                        //assert into flash
 
545
                        
 
546
                        nsCOMPtr<nsIRDFNode> urlNode;
 
547
                        distributorDataSource->GetTarget(kXPI_NotifierPackages, 
 
548
                                                         kNC_URL, 
 
549
                                                         PR_TRUE, 
 
550
                                                         getter_AddRefs(urlNode));
 
551
 
 
552
                        nsCOMPtr<nsIRDFLiteral> url(do_QueryInterface(urlNode, &rv));
 
553
                        if (NS_FAILED(rv)) break;
 
554
 
 
555
 
 
556
                        nsCOMPtr<nsIRDFNode> titleNode;
 
557
                        distributorDataSource->GetTarget(kXPI_NotifierPackages, 
 
558
                                                         kXPI_NotifierPackage_Title, 
 
559
                                                         PR_TRUE, 
 
560
                                                         getter_AddRefs(titleNode));
 
561
 
 
562
                        nsCOMPtr<nsIRDFLiteral> title(do_QueryInterface(titleNode, &rv));
 
563
                        if (NS_FAILED(rv)) break;
 
564
 
 
565
                        nsCOMPtr<nsIRDFDataSource> ds = do_QueryInterface(mNotifications);
 
566
 
 
567
                        ds->Assert(aPackage, kNC_Name, title, PR_TRUE);
 
568
                        ds->Assert(aPackage, kNC_URL, url, PR_TRUE);
 
569
 
 
570
                        ds->Assert(kNC_NotificationRoot, kNC_Child, aPackage, PR_TRUE);
 
571
                        break;
 
572
 
 
573
                    }
 
574
                }
 
575
            }
 
576
        }
 
577
    }
 
578
        VR_Close();
 
579
    return NS_OK;
 
580
}
 
581
 
 
582
 
 
583
NS_IMETHODIMP
 
584
nsXPINotifierImpl::OnError(nsIRDFXMLSink *aSink, nsresult aResult, const PRUnichar* aErrorMsg)
 
585
{
 
586
    (void) aSink->RemoveXMLSinkObserver(this);
 
587
    return NS_OK;
 
588
}
 
589
 
 
590
 
 
591
NS_IMETHODIMP
 
592
nsXPINotifierImpl::DisplayUpdateDialog(void)
 
593
{
 
594
    nsresult rv;
 
595
    nsCOMPtr <nsISimpleEnumerator> packages;
 
596
    PRBool moreElements;
 
597
 
 
598
    nsCOMPtr<nsIRDFDataSource> ds = do_QueryInterface(mNotifications, &rv);
 
599
 
 
600
    if (NS_SUCCEEDED(rv))
 
601
    {
 
602
        rv = ds->GetAllResources(getter_AddRefs(packages));
 
603
        if (NS_SUCCEEDED(rv))
 
604
        {
 
605
            packages->HasMoreElements(&moreElements);
 
606
            while (moreElements) 
 
607
            {
 
608
                nsCOMPtr<nsISupports> i;
 
609
 
 
610
                rv = packages->GetNext(getter_AddRefs(i));
 
611
                if (NS_FAILED(rv)) break;
 
612
 
 
613
                nsCOMPtr<nsIRDFResource> aPackage(do_QueryInterface(i, &rv));
 
614
                if (NS_FAILED(rv)) break;
 
615
 
 
616
                
 
617
                // Get the version information
 
618
                nsCOMPtr<nsIRDFNode> name;
 
619
                ds->GetTarget(aPackage, 
 
620
                              nsXPINotifierImpl::kNC_Name, 
 
621
                              PR_TRUE, 
 
622
                              getter_AddRefs(name));
 
623
 
 
624
                nsCOMPtr<nsIRDFLiteral> nameLiteral = do_QueryInterface(name, &rv);
 
625
                if (NS_FAILED(rv)) break;
 
626
            }
 
627
        }
 
628
    }
 
629
    return rv;
 
630
}
 
631
 
 
632
 
 
633