~ubuntu-branches/debian/stretch/downthemall/stretch

« back to all changes in this revision

Viewing changes to modules/support/metalinker.js

  • Committer: Package Import Robot
  • Author(s): Michael Meskes
  • Date: 2016-09-21 13:33:55 UTC
  • mto: This revision was merged to the branch mainline in revision 11.
  • Revision ID: package-import@ubuntu.com-20160921133355-ylst3mzzo82mghyw
Tags: upstream-3.0.6
ImportĀ upstreamĀ versionĀ 3.0.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This Source Code Form is subject to the terms of the Mozilla Public
 
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 
3
 * You can obtain one at http://mozilla.org/MPL/2.0/ */
 
4
"use strict";
 
5
 
 
6
/**
 
7
 * Metalinker3 namespace
 
8
 */
 
9
const NS_METALINKER3 = 'http://www.metalinker.org/';
 
10
/**
 
11
 * Metalinker 4 namespace
 
12
 */
 
13
const NS_METALINK_RFC5854 = 'urn:ietf:params:xml:ns:metalink';
 
14
 
 
15
const DTA = require("api");
 
16
const Preferences = require("preferences");
 
17
const {LOCALE} = require("version");
 
18
const {UrlManager} = require("./urlmanager");
 
19
const {NS_DTA, NS_HTML, normalizeMetaPrefs} = require("utils");
 
20
 
 
21
const XPathResult = Ci.nsIDOMXPathResult;
 
22
 
 
23
/**
 
24
 * Parsed Metalink representation
 
25
 * (Do not construct yourself unless you know what you're doing)
 
26
 */
 
27
function Metalink(downloads, info, parser) {
 
28
        this.downloads = downloads;
 
29
        this.info = info;
 
30
        this.parser = parser;
 
31
}
 
32
Metalink.prototype = {
 
33
        /**
 
34
         * Array of downloads
 
35
         */
 
36
        downloads: [],
 
37
        /**
 
38
         * Dict of general information
 
39
         */
 
40
        info: {},
 
41
        /**
 
42
         * Parser identifaction
 
43
         */
 
44
        parser: ""
 
45
};
 
46
 
 
47
function Base(doc, NS) {
 
48
        this._doc = doc;
 
49
        this._NS = NS;
 
50
}
 
51
Base.prototype = {
 
52
        lookupNamespaceURI: function Base_lookupNamespaceURI(prefix) {
 
53
                switch (prefix) {
 
54
                case 'html':
 
55
                        return NS_HTML;
 
56
                case 'dta':
 
57
                        return NS_DTA;
 
58
                }
 
59
                return this._NS;
 
60
        },
 
61
        getNodes: function (elem, query) {
 
62
                let rv = [];
 
63
                let iterator = this._doc.evaluate(
 
64
                        query,
 
65
                        elem,
 
66
                        this,
 
67
                        XPathResult.ORDERED_NODE_ITERATOR_TYPE,
 
68
                        null
 
69
                );
 
70
                for (let n = iterator.iterateNext(); n; n = iterator.iterateNext()) {
 
71
                        rv.push(n);
 
72
                }
 
73
                return rv;
 
74
        },
 
75
        getNode: function Base_getNode(elem, query) {
 
76
                let r = this.getNodes(elem, query);
 
77
                if (r.length) {
 
78
                        return r.shift();
 
79
                }
 
80
                return null;
 
81
        },
 
82
        getSingle: function BasegetSingle(elem, query) {
 
83
                let rv = this.getNode(elem, 'ml:' + query);
 
84
                return rv ? rv.textContent.trim() : '';
 
85
        },
 
86
        getLinkRes: function BasegetLinkRes(elem, query) {
 
87
                let rv = this.getNode(elem, 'ml:' + query);
 
88
                if (rv) {
 
89
                        let n = this.getSingle(rv, 'name'), l = this.checkURL(this.getSingle(rv, 'url'));
 
90
                        if (n && l) {
 
91
                                return [n, l];
 
92
                        }
 
93
                }
 
94
                return null;
 
95
        },
 
96
        checkURL: function Base_checkURL(url, allowed) {
 
97
                if (!url) {
 
98
                        return null;
 
99
                }
 
100
                try {
 
101
                        url = Services.io.newURI(url, this._doc.characterSet, null);
 
102
                        if (url.scheme === 'file') {
 
103
                                throw new Exception("file protocol invalid!");
 
104
                        }
 
105
                        // check for some popular bad links :p
 
106
                        if (!~['http', 'https', 'ftp'].indexOf(url.scheme) || !~url.host.indexOf('.')) {
 
107
                                if (!(allowed instanceof Array)) {
 
108
                                        throw new Exception("bad link!");
 
109
                                }
 
110
                                if (!~allowed.indexOf(url.scheme)) {
 
111
                                        throw new Exception("not allowed!");
 
112
                                }
 
113
                        }
 
114
                        return url.spec;
 
115
                }
 
116
                catch (ex) {
 
117
                        log(LOG_ERROR, "checkURL: failed to parse " + url, ex);
 
118
                        // no-op
 
119
                }
 
120
                return null;
 
121
        }
 
122
};
 
123
 
 
124
/**
 
125
 * Metalink3 Parser
 
126
 * @param doc document to parse
 
127
 * @return Metalink
 
128
 */
 
129
function Metalinker3(doc) {
 
130
        let root = doc.documentElement;
 
131
        if (root.nodeName !== 'metalink' || root.getAttribute('version') !== '3.0') {
 
132
                throw new Exception('mlinvalid');
 
133
        }
 
134
        Base.call(this, doc, NS_METALINKER3);
 
135
}
 
136
Metalinker3.prototype = {
 
137
        __proto__: Base.prototype,
 
138
        parse: function ML3_parse(aReferrer) {
 
139
                if (aReferrer && 'spec' in aReferrer) {
 
140
                        aReferrer = aReferrer.spec;
 
141
                }
 
142
 
 
143
                let doc = this._doc;
 
144
                let root = doc.documentElement;
 
145
                let downloads = [];
 
146
 
 
147
                let files = this.getNodes(doc, '//ml:files/ml:file');
 
148
 
 
149
                if (!files.length) {
 
150
                        throw new Exception("No valid file nodes");
 
151
                }
 
152
 
 
153
                for (let file of files) {
 
154
                        let fileName = file.getAttribute('name');
 
155
                        if (!fileName) {
 
156
                                throw new Exception("LocalFile name not provided!");
 
157
                        }
 
158
                        let referrer = null;
 
159
                        if (file.hasAttributeNS(NS_DTA, 'referrer')) {
 
160
                                referrer = file.getAttributeNS(NS_DTA, 'referrer');
 
161
                        }
 
162
                        else {
 
163
                                referrer = aReferrer;
 
164
                        }
 
165
                        let num = null;
 
166
                        if (file.hasAttributeNS(NS_DTA, 'num')) {
 
167
                                try {
 
168
                                        num = parseInt(file.getAttributeNS(NS_DTA, 'num'), 10);
 
169
                                }
 
170
                                catch (ex) {
 
171
                                        /* no-op */
 
172
                                }
 
173
                        }
 
174
                        if (!num) {
 
175
                                num = DTA.currentSeries();
 
176
                        }
 
177
                        let startDate = new Date();
 
178
                        if (file.hasAttributeNS(NS_DTA, 'startDate')) {
 
179
                                try {
 
180
                                        startDate = new Date(parseInt(file.getAttributeNS(NS_DTA, 'startDate'), 10));
 
181
                                }
 
182
                                catch (ex) {
 
183
                                        /* no-op */
 
184
                                }
 
185
                        }
 
186
 
 
187
                        let urls = [];
 
188
                        let urlNodes = this.getNodes(file, 'ml:resources/ml:url');
 
189
                        for (var url of urlNodes) {
 
190
                                let preference = 1;
 
191
                                let charset = doc.characterSet;
 
192
                                if (url.hasAttributeNS(NS_DTA, 'charset')) {
 
193
                                        charset = url.getAttributeNS(NS_DTA, 'charset');
 
194
                                }
 
195
 
 
196
                                let uri = null;
 
197
                                try {
 
198
                                        if (url.hasAttribute('type') && !url.getAttribute('type').match(/^(?:https?|ftp)$/i)) {
 
199
                                                throw new Exception("Invalid url type");
 
200
                                        }
 
201
                                        uri = this.checkURL(url.textContent.trim());
 
202
                                        if (!uri) {
 
203
                                                throw new Exception("Invalid url");
 
204
                                        }
 
205
                                        else if(!url.hasAttribute('type') && uri.substr(-8) === ".torrent") {
 
206
                                                throw new Exception("Torrent downloads not supported");
 
207
                                        }
 
208
                                        uri = Services.io.newURI(uri, charset, null);
 
209
                                }
 
210
                                catch (ex) {
 
211
                                        log(LOG_ERROR, "Failed to parse URL" + url.textContent, ex);
 
212
                                        continue;
 
213
                                }
 
214
 
 
215
                                if (url.hasAttribute('preference')) {
 
216
                                        let a = parseInt(url.getAttribute('preference'), 10);
 
217
                                        if (isFinite(a) && a > 0 && a < 101) {
 
218
                                                preference = a;
 
219
                                        }
 
220
                                }
 
221
                                if (url.hasAttribute('location')) {
 
222
                                        let a = url.getAttribute('location').slice(0,2).toLowerCase();
 
223
                                        if (~LOCALE.indexOf(a)) {
 
224
                                                preference = 100 + preference;
 
225
                                        }
 
226
                                }
 
227
                                urls.push(new DTA.URL(uri, preference));
 
228
                        }
 
229
                        if (!urls.length) {
 
230
                                continue;
 
231
                        }
 
232
                        let size = this.getSingle(file, 'size');
 
233
                        size = parseInt(size, 10);
 
234
                        if (!isFinite(size)) {
 
235
                                size = 0;
 
236
                        }
 
237
 
 
238
                        let hash = null;
 
239
                        for (let h of this.getNodes(file, 'ml:verification/ml:hash')) {
 
240
                                try {
 
241
                                        h = new DTA.Hash(h.textContent.trim(), h.getAttribute('type'));
 
242
                                        if (!hash || hash.q < h.q) {
 
243
                                                hash = h;
 
244
                                        }
 
245
                                }
 
246
                                catch (ex) {
 
247
                                        log(LOG_ERROR, "Failed to parse hash: " + h.textContent.trim() + "/" + h.getAttribute('type'), ex);
 
248
                                }
 
249
                        }
 
250
                        if (hash) {
 
251
                                hash = new DTA.HashCollection(hash);
 
252
                                let pieces = this.getNodes(file, 'ml:verification/ml:pieces');
 
253
                                if (pieces.length) {
 
254
                                        pieces = pieces[0];
 
255
                                        let type = pieces.getAttribute('type').trim();
 
256
                                        try {
 
257
                                                hash.parLength = parseInt(pieces.getAttribute('length'), 10);
 
258
                                                if (!isFinite(hash.parLength) || hash.parLength < 1) {
 
259
                                                        throw new Exception("Invalid pieces length");
 
260
                                                }
 
261
                                                let collection = [];
 
262
                                                let maxPiece = Math.ceil(size / hash.parLength);
 
263
                                                for (let piece of this.getNodes(pieces, 'ml:hash')) {
 
264
                                                        try {
 
265
                                                                let num = parseInt(piece.getAttribute('piece'), 10);
 
266
                                                                if (!maxPiece || (num >= 0 && num <= maxPiece)) {
 
267
                                                                        collection[num] =  new DTA.Hash(piece.textContent.trim(), type);
 
268
                                                                }
 
269
                                                                else {
 
270
                                                                        throw new Exception("out of bound piece");
 
271
                                                                }
 
272
                                                        }
 
273
                                                        catch (ex) {
 
274
                                                                log(LOG_ERROR, "Failed to parse piece", ex);
 
275
                                                                throw ex;
 
276
                                                        }
 
277
                                                }
 
278
                                                let totalPieces = maxPiece || collection.length;
 
279
                                                for (let i = 0; i < totalPieces; i++) {
 
280
                                                        if (collection[i]) {
 
281
                                                                hash.add(collection[i]);
 
282
                                                        }
 
283
                                                        else {
 
284
                                                                throw new Exception("missing piece");
 
285
                                                        }
 
286
                                                }
 
287
                                                log(LOG_DEBUG, "loaded " + hash.partials.length + " partials");
 
288
                                        }
 
289
                                        catch (ex) {
 
290
                                                log(LOG_ERROR, "Failed to parse pieces", ex);
 
291
                                                hash = new DTA.HashCollection(hash.full);
 
292
                                        }
 
293
                                }
 
294
                        }
 
295
                        let desc = this.getSingle(file, 'description');
 
296
                        if (!desc) {
 
297
                                desc = this.getSingle(root, 'description');
 
298
                        }
 
299
 
 
300
                        downloads.push({
 
301
                                'url': new UrlManager(urls),
 
302
                                'fileName': fileName,
 
303
                                'referrer': referrer ? referrer : null,
 
304
                                'numIstance': num,
 
305
                                'title': '',
 
306
                                'description': desc,
 
307
                                'startDate': startDate,
 
308
                                'hashCollection': hash,
 
309
                                'license': this.getLinkRes(file, "license"),
 
310
                                'publisher': this.getLinkRes(file, "publisher"),
 
311
                                'identity': this.getSingle(file, 'identity'),
 
312
                                'copyright': this.getSingle(file, 'copyright'),
 
313
                                'size': size,
 
314
                                'version': this.getSingle(file, 'version'),
 
315
                                'logo': this.checkURL(this.getSingle(file, 'logo', ['data'])),
 
316
                                'lang': this.getSingle(file, 'language'),
 
317
                                'sys': this.getSingle(file, 'os'),
 
318
                                'mirrors': urls.length,
 
319
                                'selected': true,
 
320
                                'fromMetalink': true
 
321
                        });
 
322
                }
 
323
 
 
324
                if (!downloads.length) {
 
325
                        throw new Exception("No valid files to process");
 
326
                }
 
327
                let info = {
 
328
                        'identity': this.getSingle(root, 'identity'),
 
329
                        'description': this.getSingle(root, 'description'),
 
330
                        'logo': this.checkURL(this.getSingle(root, 'logo', ['data'])),
 
331
                        'license': this.getLinkRes(root, "license"),
 
332
                        'publisher': this.getLinkRes(root, "publisher"),
 
333
                        'start': false
 
334
                };
 
335
                return new Metalink(downloads, info, "Metalinker Version 3.0");
 
336
        }
 
337
};
 
338
 
 
339
/**
 
340
 * Metalink RFC5854 (IETF) Parser
 
341
 * @param doc document to parse
 
342
 * @return Metalink
 
343
 */
 
344
function MetalinkerRFC5854(doc) {
 
345
        let root = doc.documentElement;
 
346
        if (root.nodeName !== 'metalink' || root.namespaceURI !== NS_METALINK_RFC5854 ) {
 
347
                if (log.enabled) {
 
348
                        log(LOG_DEBUG, root.nodeName + "\nns:" + root.namespaceURI);
 
349
                }
 
350
                throw new Exception('mlinvalid');
 
351
        }
 
352
        Base.call(this, doc, NS_METALINK_RFC5854);
 
353
}
 
354
MetalinkerRFC5854.prototype = {
 
355
        __proto__: Base.prototype,
 
356
        parse: function ML4_parse(aReferrer) {
 
357
                if (aReferrer && 'spec' in aReferrer) {
 
358
                        aReferrer = aReferrer.spec;
 
359
                }
 
360
 
 
361
                let doc = this._doc;
 
362
                let root = doc.documentElement;
 
363
                let downloads = [];
 
364
 
 
365
                let files = this.getNodes(doc, '/ml:metalink/ml:file');
 
366
                if (!files.length) {
 
367
                        throw new Exception("No valid file nodes");
 
368
                }
 
369
                for (let file of files) {
 
370
                        let fileName = file.getAttribute('name');
 
371
                        if (!fileName) {
 
372
                                throw new Exception("LocalFile name not provided!");
 
373
                        }
 
374
                        let referrer = null;
 
375
                        if (file.hasAttributeNS(NS_DTA, 'referrer')) {
 
376
                                referrer = file.getAttributeNS(NS_DTA, 'referrer');
 
377
                        }
 
378
                        else {
 
379
                                referrer = aReferrer;
 
380
                        }
 
381
                        let num = null;
 
382
                        if (file.hasAttributeNS(NS_DTA, 'num')) {
 
383
                                try {
 
384
                                        num = parseInt(file.getAttributeNS(NS_DTA, 'num'), 10);
 
385
                                }
 
386
                                catch (ex) {
 
387
                                        /* no-op */
 
388
                                }
 
389
                        }
 
390
                        if (!num) {
 
391
                                num = DTA.currentSeries();
 
392
                        }
 
393
                        let startDate = new Date();
 
394
                        if (file.hasAttributeNS(NS_DTA, 'startDate')) {
 
395
                                try {
 
396
                                        startDate = new Date(parseInt(file.getAttributeNS(NS_DTA, 'startDate'), 10));
 
397
                                }
 
398
                                catch (ex) {
 
399
                                        /* no-op */
 
400
                                }
 
401
                        }
 
402
 
 
403
                        let urls = [];
 
404
                        let urlNodes = this.getNodes(file, 'ml:url');
 
405
                        for (var url of urlNodes) {
 
406
                                let preference = 1;
 
407
                                let charset = doc.characterSet;
 
408
                                if (url.hasAttributeNS(NS_DTA, 'charset')) {
 
409
                                        charset = url.getAttributeNS(NS_DTA, 'charset');
 
410
                                }
 
411
 
 
412
                                let uri = null;
 
413
                                try {
 
414
                                        uri = this.checkURL(url.textContent.trim());
 
415
                                        if (!uri) {
 
416
                                                throw new Exception("Invalid url");
 
417
                                        }
 
418
                                        uri = Services.io.newURI(uri, charset, null);
 
419
                                }
 
420
                                catch (ex) {
 
421
                                        log(LOG_ERROR, "Failed to parse URL" + url.textContent, ex);
 
422
                                        continue;
 
423
                                }
 
424
 
 
425
                                if (url.hasAttribute('priority')) {
 
426
                                        let a = parseInt(url.getAttribute('priority'), 10);
 
427
                                        if (a > 0) {
 
428
                                                preference = a;
 
429
                                        }
 
430
                                }
 
431
                                if (url.hasAttribute('location')) {
 
432
                                        let a = url.getAttribute('location').slice(0,2).toLowerCase();
 
433
                                        if (~LOCALE.indexOf(a)) {
 
434
                                                preference = Math.max(preference / 4, 1);
 
435
                                        }
 
436
                                }
 
437
                                urls.push(new DTA.URL(uri, preference));
 
438
                        }
 
439
                        if (!urls.length) {
 
440
                                continue;
 
441
                        }
 
442
                        normalizeMetaPrefs(urls);
 
443
 
 
444
                        let size = this.getSingle(file, 'size');
 
445
                        size = parseInt(size, 10);
 
446
                        if (!isFinite(size)) {
 
447
                                size = 0;
 
448
                        }
 
449
 
 
450
                        let hash = null;
 
451
                        for (let h of this.getNodes(file, 'ml:hash')) {
 
452
                                try {
 
453
                                        h = new DTA.Hash(h.textContent.trim(), h.getAttribute('type'));
 
454
                                        if (!hash || hash.q < h.q) {
 
455
                                                hash = h;
 
456
                                        }
 
457
                                }
 
458
                                catch (ex) {
 
459
                                        log(LOG_ERROR, "Failed to parse hash: " + h.textContent.trim() + "/" + h.getAttribute('type'), ex);
 
460
                                }
 
461
                        }
 
462
                        if (hash) {
 
463
                                hash = new DTA.HashCollection(hash);
 
464
                                let pieces = this.getNodes(file, 'ml:pieces');
 
465
                                if (pieces.length) {
 
466
                                        pieces = pieces[0];
 
467
                                        let type = pieces.getAttribute('type').trim();
 
468
                                        try {
 
469
                                                hash.parLength = parseInt(pieces.getAttribute('length'), 10);
 
470
                                                if (!isFinite(hash.parLength) || hash.parLength < 1) {
 
471
                                                        throw new Exception("Invalid pieces length");
 
472
                                                }
 
473
                                                for (let piece of this.getNodes(pieces, 'ml:hash')) {
 
474
                                                        try {
 
475
                                                                hash.add(new DTA.Hash(piece.textContent.trim(), type));
 
476
                                                        }
 
477
                                                        catch (ex) {
 
478
                                                                log(LOG_ERROR, "Failed to parse piece", ex);
 
479
                                                                throw ex;
 
480
                                                        }
 
481
                                                }
 
482
                                                if (size && hash.parLength * hash.partials.length < size) {
 
483
                                                        throw new Exception("too few partials");
 
484
                                                }
 
485
                                                else if(size && (hash.partials.length - 1) * hash.parLength > size) {
 
486
                                                        throw new Exception("too many partials");
 
487
                                                }
 
488
                                                log(LOG_DEBUG, "loaded " + hash.partials.length + " partials");
 
489
                                        }
 
490
                                        catch (ex) {
 
491
                                                log(LOG_ERROR, "Failed to parse pieces", ex);
 
492
                                                hash = new DTA.HashCollection(hash.full);
 
493
                                        }
 
494
                                }
 
495
                        }
 
496
 
 
497
                        let desc = this.getSingle(file, 'description');
 
498
                        if (!desc) {
 
499
                                desc = this.getSingle(root, 'description');
 
500
                        }
 
501
                        downloads.push({
 
502
                                'url': new UrlManager(urls),
 
503
                                'fileName': fileName,
 
504
                                'referrer': referrer ? referrer : null,
 
505
                                'numIstance': num,
 
506
                                'title': '',
 
507
                                'description': desc,
 
508
                                'startDate': startDate,
 
509
                                'hashCollection': hash,
 
510
                                'license': this.getLinkRes(file, "license"),
 
511
                                'publisher': this.getLinkRes(file, "publisher"),
 
512
                                'identity': this.getSingle(file, "identity"),
 
513
                                'copyright': this.getSingle(file, "copyright"),
 
514
                                'size': size,
 
515
                                'version': this.getSingle(file, "version"),
 
516
                                'logo': this.checkURL(this.getSingle(file, "logo", ['data'])),
 
517
                                'lang': this.getSingle(file, "language"),
 
518
                                'sys': this.getSingle(file, "os"),
 
519
                                'mirrors': urls.length,
 
520
                                'selected': true,
 
521
                                'fromMetalink': true
 
522
                        });
 
523
                }
 
524
 
 
525
                if (!downloads.length) {
 
526
                        throw new Exception("No valid files to process");
 
527
                }
 
528
 
 
529
                let info = {
 
530
                        'identity': this.getSingle(root, "identity"),
 
531
                        'description': this.getSingle(root, "description"),
 
532
                        'logo': this.checkURL(this.getSingle(root, "logo", ['data'])),
 
533
                        'license': this.getLinkRes(root, "license"),
 
534
                        'publisher': this.getLinkRes(root, "publisher"),
 
535
                        'start': false
 
536
                };
 
537
                return new Metalink(downloads, info, "Metalinker Version 4.0 (RFC5854/IETF)");
 
538
        }
 
539
};
 
540
 
 
541
const __parsers__ = [
 
542
        Metalinker3,
 
543
        MetalinkerRFC5854
 
544
];
 
545
 
 
546
/**
 
547
 * Parse a metalink
 
548
 * @param aURI (nsIURI) Metalink URI
 
549
 * @param aReferrer (String) Optional. Referrer
 
550
 * @param aCallback (Function) Receiving callback function of form f(result, exception || null)
 
551
 * @return async (Metalink) Parsed metalink data
 
552
 */
 
553
function parse(aURI, aReferrer, aCallback) {
 
554
        let xhrLoad, xhrError;
 
555
        let xhr = new Instances.XHR();
 
556
        xhr.open("GET", aURI.spec);
 
557
        log(LOG_DEBUG, "parsing metalink at " + aURI.spec);
 
558
        xhr.overrideMimeType("application/xml");
 
559
        xhr.addEventListener("loadend", function xhrLoadend() {
 
560
                xhr.removeEventListener("loadend", xhrLoadend, false);
 
561
                try {
 
562
                        let doc = xhr.responseXML;
 
563
                        if (doc.documentElement.nodeName === 'parsererror') {
 
564
                                throw new Exception("Failed to parse XML");
 
565
                        }
 
566
                        for (let Parser of __parsers__) {
 
567
                                let parser;
 
568
                                try {
 
569
                                        parser = new Parser(doc);
 
570
                                }
 
571
                                catch (ex) {
 
572
                                        log(LOG_DEBUG, Parser.name + " failed", ex);
 
573
                                        continue;
 
574
                                }
 
575
                                aCallback(parser.parse(aReferrer));
 
576
                                return;
 
577
                        }
 
578
                        throw new Exception("no suitable parser found!");
 
579
                }
 
580
                catch (ex) {
 
581
                        log(LOG_ERROR, "Failed to parse metalink", ex);
 
582
                        aCallback(null, ex);
 
583
                }
 
584
        }, false);
 
585
        xhr.send();
 
586
}
 
587
 
 
588
Object.defineProperties(exports, {
 
589
        "parse": {value: parse, enumerable: true},
 
590
        "Metalink": {value: Metalink, enumerable: true},
 
591
        "NS_DTA": {value: NS_DTA, enumerable: true},
 
592
        "NS_HTML": {value: NS_HTML, enumerable: true},
 
593
        "NS_METALINKER3": {value: NS_METALINKER3, enumerable: true},
 
594
        "NS_METALINK_RFC5854": {value: NS_METALINK_RFC5854, enumerable: true}
 
595
});
 
596
Object.freeze(exports);