Jeff Thompson | 08ab3cd | 2012-10-08 02:56:20 -0700 | [diff] [blame] | 1 | /*
|
Jeff Thompson | 17a9da8 | 2012-11-12 01:11:01 -0800 | [diff] [blame] | 2 | * @author: Jeff Thompson
|
Jeff Thompson | 745026e | 2012-10-13 12:49:20 -0700 | [diff] [blame] | 3 | * See COPYING for copyright and distribution information.
|
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 4 | * This is the ndn protocol handler.
|
Jeff Thompson | 08ab3cd | 2012-10-08 02:56:20 -0700 | [diff] [blame] | 5 | * Protocol handling code derived from http://mike.kaply.com/2011/01/18/writing-a-firefox-protocol-handler/
|
| 6 | */
|
| 7 |
|
| 8 | const Cc = Components.classes;
|
| 9 | const Ci = Components.interfaces;
|
| 10 | const Cr = Components.results;
|
| 11 |
|
| 12 | const nsIProtocolHandler = Ci.nsIProtocolHandler;
|
| 13 |
|
| 14 | Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
|
| 15 | Components.utils.import("chrome://modules/content/ndn-js.jsm");
|
| 16 | Components.utils.import("chrome://modules/content/ContentChannel.jsm");
|
Jeff Thompson | 6ad5c36 | 2012-12-27 17:57:02 -0800 | [diff] [blame] | 17 | Components.utils.import("chrome://modules/content/NdnProtocolInfo.jsm");
|
Jeff Thompson | 08ab3cd | 2012-10-08 02:56:20 -0700 | [diff] [blame] | 18 |
|
Jeff Thompson | 74d38e3 | 2013-03-18 21:44:07 -0700 | [diff] [blame] | 19 | function NdnProtocol() {
|
Jeff Thompson | 08ab3cd | 2012-10-08 02:56:20 -0700 | [diff] [blame] | 20 | }
|
| 21 |
|
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 22 | NdnProtocol.prototype = {
|
| 23 | scheme: "ndn",
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 24 | protocolFlags: nsIProtocolHandler.URI_NORELATIVE |
|
Jeff Thompson | 08ab3cd | 2012-10-08 02:56:20 -0700 | [diff] [blame] | 25 | nsIProtocolHandler.URI_NOAUTH |
|
| 26 | nsIProtocolHandler.URI_LOADABLE_BY_ANYONE,
|
| 27 |
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 28 | newURI: function(aSpec, aOriginCharset, aBaseURI)
|
| 29 | {
|
Jeff Thompson | 2cc54b4 | 2013-01-12 23:11:12 -0800 | [diff] [blame] | 30 | var uri = Cc["@mozilla.org/network/simple-uri;1"].createInstance(Ci.nsIURI);
|
| 31 |
|
Jeff Thompson | d6b61e4 | 2012-11-24 12:10:35 -0800 | [diff] [blame] | 32 | // We have to trim now because nsIURI converts spaces to %20 and we can't trim in newChannel.
|
Jeff Thompson | b2f91ea | 2013-01-13 15:59:26 -0800 | [diff] [blame] | 33 | var uriParts = NdnProtocolInfo.splitUri(aSpec);
|
Jeff Thompson | 2cc54b4 | 2013-01-12 23:11:12 -0800 | [diff] [blame] | 34 | if (aBaseURI == null || uriParts.name.length < 1 || uriParts.name[0] == '/')
|
| 35 | // Just reconstruct the trimmed URI.
|
| 36 | uri.spec = "ndn:" + uriParts.name + uriParts.search + uriParts.hash;
|
| 37 | else {
|
| 38 | // Make a URI relative to the base name up to the file name component.
|
Jeff Thompson | b2f91ea | 2013-01-13 15:59:26 -0800 | [diff] [blame] | 39 | var baseUriParts = NdnProtocolInfo.splitUri(aBaseURI.spec);
|
Jeff Thompson | 2cc54b4 | 2013-01-12 23:11:12 -0800 | [diff] [blame] | 40 | var baseName = new Name(baseUriParts.name);
|
| 41 | var iFileName = baseName.indexOfFileName();
|
| 42 |
|
| 43 | var relativeName = uriParts.name;
|
| 44 | // Handle ../
|
| 45 | while (true) {
|
| 46 | if (relativeName.substr(0, 2) == "./")
|
| 47 | relativeName = relativeName.substr(2);
|
| 48 | else if (relativeName.substr(0, 3) == "../") {
|
| 49 | relativeName = relativeName.substr(3);
|
| 50 | if (iFileName > 0)
|
| 51 | --iFileName;
|
| 52 | }
|
| 53 | else
|
| 54 | break;
|
| 55 | }
|
| 56 |
|
| 57 | var prefixUri = "/";
|
| 58 | if (iFileName > 0)
|
| 59 | prefixUri = new Name(baseName.components.slice(0, iFileName)).to_uri() + "/";
|
| 60 | uri.spec = "ndn:" + prefixUri + relativeName + uriParts.search + uriParts.hash;
|
| 61 | }
|
| 62 |
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 63 | return uri;
|
| 64 | },
|
Jeff Thompson | 08ab3cd | 2012-10-08 02:56:20 -0700 | [diff] [blame] | 65 |
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 66 | newChannel: function(aURI)
|
| 67 | {
|
Jeff Thompson | 1eea632 | 2012-11-23 16:56:18 -0800 | [diff] [blame] | 68 | try {
|
Jeff Thompson | b2f91ea | 2013-01-13 15:59:26 -0800 | [diff] [blame] | 69 | var uriParts = NdnProtocolInfo.splitUri(aURI.spec);
|
Jeff Thompson | df0a6f7 | 2012-10-21 15:58:58 -0700 | [diff] [blame] | 70 |
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 71 | var template = new Interest(new Name([]));
|
| 72 | // Use the same default as NDN.expressInterest.
|
Jeff Thompson | 42806a1 | 2012-12-29 18:19:39 -0800 | [diff] [blame] | 73 | template.interestLifetime = 4000; // milliseconds
|
Jeff Thompson | 8107ec8 | 2013-01-12 21:53:27 -0800 | [diff] [blame] | 74 | var searchWithoutNdn = extractNdnSearch(uriParts.search, template);
|
Jeff Thompson | e5a8828 | 2013-01-05 21:02:06 -0800 | [diff] [blame] | 75 |
|
| 76 | var segmentTemplate = new Interest(new Name([]));
|
| 77 | // Only use the interest selectors which make sense for fetching further segments.
|
| 78 | segmentTemplate.publisherPublicKeyDigest = template.publisherPublicKeyDigest;
|
| 79 | segmentTemplate.scope = template.scope;
|
| 80 | segmentTemplate.interestLifetime = template.interestLifetime;
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 81 |
|
Jeff Thompson | 1eea632 | 2012-11-23 16:56:18 -0800 | [diff] [blame] | 82 | var requestContent = function(contentListener) {
|
Jeff Thompson | 8107ec8 | 2013-01-12 21:53:27 -0800 | [diff] [blame] | 83 | var name = new Name(uriParts.name);
|
Jeff Thompson | 3d6ce94 | 2012-12-16 12:11:42 -0800 | [diff] [blame] | 84 | // Use the same NDN object each time.
|
Jeff Thompson | 4eb992a | 2013-03-09 21:05:53 -0800 | [diff] [blame] | 85 | NdnProtocolInfo.ndn.expressInterest(name, new ExponentialReExpressClosure
|
| 86 | (new ContentClosure(NdnProtocolInfo.ndn, contentListener, name,
|
Jeff Thompson | 52843b1 | 2013-02-18 17:53:18 -0800 | [diff] [blame] | 87 | aURI, searchWithoutNdn + uriParts.hash, segmentTemplate)),
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 88 | template);
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 89 | };
|
Jeff Thompson | 57d0738 | 2012-10-29 23:25:54 -0700 | [diff] [blame] | 90 |
|
Jeff Thompson | f998ef1 | 2013-03-31 14:44:58 -0700 | [diff] [blame^] | 91 | var contentChannel = new ContentChannel(aURI, requestContent);
|
| 92 | return contentChannel;
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 93 | } catch (ex) {
|
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 94 | dump("NdnProtocol.newChannel exception: " + ex + "\n" + ex.stack);
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 95 | }
|
| 96 | },
|
Jeff Thompson | 08ab3cd | 2012-10-08 02:56:20 -0700 | [diff] [blame] | 97 |
|
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 98 | classDescription: "ndn Protocol Handler",
|
| 99 | contractID: "@mozilla.org/network/protocol;1?name=" + "ndn",
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 100 | classID: Components.ID('{8122e660-1012-11e2-892e-0800200c9a66}'),
|
| 101 | QueryInterface: XPCOMUtils.generateQI([Ci.nsIProtocolHandler])
|
Jeff Thompson | 3d6ce94 | 2012-12-16 12:11:42 -0800 | [diff] [blame] | 102 | };
|
Jeff Thompson | 08ab3cd | 2012-10-08 02:56:20 -0700 | [diff] [blame] | 103 |
|
| 104 | if (XPCOMUtils.generateNSGetFactory)
|
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 105 | var NSGetFactory = XPCOMUtils.generateNSGetFactory([NdnProtocol]);
|
Jeff Thompson | 08ab3cd | 2012-10-08 02:56:20 -0700 | [diff] [blame] | 106 | else
|
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 107 | var NSGetModule = XPCOMUtils.generateNSGetModule([NdnProtocol]);
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 108 |
|
| 109 | /*
|
| 110 | * Create a closure for calling expressInterest.
|
| 111 | * contentListener is from the call to requestContent.
|
Jeff Thompson | 4a4caba | 2013-02-28 21:31:33 -0800 | [diff] [blame] | 112 | * uriName is the name in the URI passed to newChannel (used in part to determine whether to request
|
| 113 | * only that segment number and for updating the URL bar).
|
Jeff Thompson | 3663c67 | 2013-02-04 23:22:11 -0800 | [diff] [blame] | 114 | * aURI is the URI passed to newChannel.
|
Jeff Thompson | 1eea632 | 2012-11-23 16:56:18 -0800 | [diff] [blame] | 115 | * uriSearchAndHash is the search and hash part of the URI passed to newChannel, including the '?'
|
| 116 | * and/or '#' but without the interest selector fields.
|
Jeff Thompson | e5a8828 | 2013-01-05 21:02:06 -0800 | [diff] [blame] | 117 | * segmentTemplate is the template used in expressInterest to fetch further segments.
|
Jeff Thompson | 52843b1 | 2013-02-18 17:53:18 -0800 | [diff] [blame] | 118 | * The uses ExponentialReExpressClosure in expressInterest to re-express if fetching a segment times out.
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 119 | */
|
| 120 | var ContentClosure = function ContentClosure
|
Jeff Thompson | 4a4caba | 2013-02-28 21:31:33 -0800 | [diff] [blame] | 121 | (ndn, contentListener, uriName, aURI, uriSearchAndHash, segmentTemplate) {
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 122 | // Inherit from Closure.
|
| 123 | Closure.call(this);
|
| 124 |
|
| 125 | this.ndn = ndn;
|
| 126 | this.contentListener = contentListener;
|
Jeff Thompson | 4a4caba | 2013-02-28 21:31:33 -0800 | [diff] [blame] | 127 | this.uriName = uriName;
|
Jeff Thompson | 3663c67 | 2013-02-04 23:22:11 -0800 | [diff] [blame] | 128 | this.aURI = aURI;
|
Jeff Thompson | 1eea632 | 2012-11-23 16:56:18 -0800 | [diff] [blame] | 129 | this.uriSearchAndHash = uriSearchAndHash;
|
Jeff Thompson | e5a8828 | 2013-01-05 21:02:06 -0800 | [diff] [blame] | 130 | this.segmentTemplate = segmentTemplate;
|
Jeff Thompson | 1eea632 | 2012-11-23 16:56:18 -0800 | [diff] [blame] | 131 |
|
Jeff Thompson | f6995b5 | 2013-01-23 21:21:16 -0800 | [diff] [blame] | 132 | this.segmentStore = new SegmentStore();
|
Jeff Thompson | 74d38e3 | 2013-03-18 21:44:07 -0700 | [diff] [blame] | 133 | this.contentSha256 = Cc["@mozilla.org/security/hash;1"].createInstance(Ci.nsICryptoHash);
|
| 134 | this.contentSha256.init(this.contentSha256.SHA256);
|
Jeff Thompson | f6995b5 | 2013-01-23 21:21:16 -0800 | [diff] [blame] | 135 | this.didRequestFinalSegment = false;
|
| 136 | this.finalSegmentNumber = null;
|
Jeff Thompson | 52843b1 | 2013-02-18 17:53:18 -0800 | [diff] [blame] | 137 | this.didOnStart = false;
|
Jeff Thompson | 4a4caba | 2013-02-28 21:31:33 -0800 | [diff] [blame] | 138 | this.uriEndsWithSegmentNumber = endsWithSegmentNumber(uriName);
|
Jeff Thompson | 7fb08bf | 2013-03-15 00:13:10 -0700 | [diff] [blame] | 139 | this.nameWithoutSegment = null;
|
Jeff Thompson | 9c7d691 | 2013-03-15 00:53:27 -0700 | [diff] [blame] | 140 | this.excludedMetaComponents = [];
|
| 141 | this.iMetaComponent = null;
|
Jeff Thompson | 3d6ce94 | 2012-12-16 12:11:42 -0800 | [diff] [blame] | 142 | };
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 143 |
|
| 144 | ContentClosure.prototype.upcall = function(kind, upcallInfo) {
|
Jeff Thompson | f6995b5 | 2013-01-23 21:21:16 -0800 | [diff] [blame] | 145 | try {
|
Jeff Thompson | f998ef1 | 2013-03-31 14:44:58 -0700 | [diff] [blame^] | 146 | if (this.contentListener.isDone())
|
Jeff Thompson | 3663c67 | 2013-02-04 23:22:11 -0800 | [diff] [blame] | 147 | // We are getting unexpected extra results.
|
| 148 | return Closure.RESULT_ERR;
|
| 149 |
|
| 150 | if (kind == Closure.UPCALL_INTEREST_TIMED_OUT) {
|
Jeff Thompson | 152342b | 2013-02-18 20:36:53 -0800 | [diff] [blame] | 151 | if (!this.didOnStart) {
|
Jeff Thompson | 7e2e2e2 | 2013-03-10 16:41:37 -0700 | [diff] [blame] | 152 | // We have not received a segment to start the content yet, so assume the URI can't be fetched.
|
Jeff Thompson | 3663c67 | 2013-02-04 23:22:11 -0800 | [diff] [blame] | 153 | this.contentListener.onStart("text/plain", "utf-8", this.aURI);
|
| 154 | this.contentListener.onReceivedContent
|
Jeff Thompson | 152342b | 2013-02-18 20:36:53 -0800 | [diff] [blame] | 155 | ("The latest interest timed out after " + upcallInfo.interest.interestLifetime + " milliseconds.");
|
Jeff Thompson | 3663c67 | 2013-02-04 23:22:11 -0800 | [diff] [blame] | 156 | this.contentListener.onStop();
|
| 157 | return Closure.RESULT_OK;
|
| 158 | }
|
| 159 | else
|
Jeff Thompson | 52843b1 | 2013-02-18 17:53:18 -0800 | [diff] [blame] | 160 | // ExponentialReExpressClosure already tried to re-express, so quit.
|
Jeff Thompson | 3663c67 | 2013-02-04 23:22:11 -0800 | [diff] [blame] | 161 | return Closure.RESULT_ERR;
|
| 162 | }
|
| 163 |
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 164 | if (!(kind == Closure.UPCALL_CONTENT ||
|
| 165 | kind == Closure.UPCALL_CONTENT_UNVERIFIED))
|
| 166 | // The upcall is not for us.
|
| 167 | return Closure.RESULT_ERR;
|
| 168 |
|
| 169 | var contentObject = upcallInfo.contentObject;
|
| 170 | if (contentObject.content == null) {
|
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 171 | dump("NdnProtocol.ContentClosure: contentObject.content is null\n");
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 172 | return Closure.RESULT_ERR;
|
| 173 | }
|
Jeff Thompson | 6ad5c36 | 2012-12-27 17:57:02 -0800 | [diff] [blame] | 174 |
|
Jeff Thompson | 7e2e2e2 | 2013-03-10 16:41:37 -0700 | [diff] [blame] | 175 | // Assume this is only called once we're connected, report the host and port.
|
| 176 | NdnProtocolInfo.setConnectedNdnHub(this.ndn.host, this.ndn.port);
|
| 177 |
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 178 | // If !this.uriEndsWithSegmentNumber, we use the segmentNumber to load multiple segments.
|
Jeff Thompson | f6995b5 | 2013-01-23 21:21:16 -0800 | [diff] [blame] | 179 | // If this.uriEndsWithSegmentNumber, then we leave segmentNumber null.
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 180 | var segmentNumber = null;
|
Jeff Thompson | 7fb08bf | 2013-03-15 00:13:10 -0700 | [diff] [blame] | 181 | if (!this.uriEndsWithSegmentNumber && endsWithSegmentNumber(contentObject.name))
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 182 | segmentNumber = DataUtils.bigEndianToUnsignedInt
|
| 183 | (contentObject.name.components[contentObject.name.components.length - 1]);
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 184 |
|
Jeff Thompson | 52843b1 | 2013-02-18 17:53:18 -0800 | [diff] [blame] | 185 | if ((segmentNumber == null || segmentNumber == 0) && !this.didOnStart) {
|
Jeff Thompson | 4a4caba | 2013-02-28 21:31:33 -0800 | [diff] [blame] | 186 | // This is the first or only segment.
|
Jeff Thompson | 4a4caba | 2013-02-28 21:31:33 -0800 | [diff] [blame] | 187 | var iMetaComponent = getIndexOfMetaComponent(contentObject.name);
|
| 188 | if (!this.uriEndsWithSegmentNumber && iMetaComponent >= 0 &&
|
| 189 | getIndexOfMetaComponent(this.uriName) < 0) {
|
Jeff Thompson | 7fb08bf | 2013-03-15 00:13:10 -0700 | [diff] [blame] | 190 | // The matched content name has a META component that wasn't requested in the original
|
| 191 | // URI. Add this to the excluded META components to try to get the "real" content.
|
Jeff Thompson | 4a4caba | 2013-02-28 21:31:33 -0800 | [diff] [blame] | 192 | var nameWithoutMeta = new Name(contentObject.name.components.slice(0, iMetaComponent));
|
Jeff Thompson | 9c7d691 | 2013-03-15 00:53:27 -0700 | [diff] [blame] | 193 | if (this.excludedMetaComponents.length > 0 && iMetaComponent != this.iMetaComponent)
|
| 194 | // We are excluding META components at a new position in the name, so start over.
|
| 195 | this.excludedMetaComponents = [];
|
| 196 | this.iMetaComponent = iMetaComponent;
|
| 197 | this.excludedMetaComponents.push(contentObject.name.components[iMetaComponent]);
|
| 198 | // Exclude components are required to be sorted.
|
| 199 | this.excludedMetaComponents.sort(Exclude.compareComponents);
|
Jeff Thompson | 4a4caba | 2013-02-28 21:31:33 -0800 | [diff] [blame] | 200 |
|
Jeff Thompson | 9c7d691 | 2013-03-15 00:53:27 -0700 | [diff] [blame] | 201 | var excludeMetaTemplate = this.segmentTemplate.clone();
|
| 202 | excludeMetaTemplate.exclude = new Exclude(this.excludedMetaComponents);
|
Jeff Thompson | 4a4caba | 2013-02-28 21:31:33 -0800 | [diff] [blame] | 203 | this.ndn.expressInterest
|
| 204 | (nameWithoutMeta, new ExponentialReExpressClosure(this), excludeMetaTemplate);
|
Jeff Thompson | 7fb08bf | 2013-03-15 00:13:10 -0700 | [diff] [blame] | 205 | return Closure.RESULT_OK;
|
Jeff Thompson | 4a4caba | 2013-02-28 21:31:33 -0800 | [diff] [blame] | 206 | }
|
Jeff Thompson | 4a4caba | 2013-02-28 21:31:33 -0800 | [diff] [blame] | 207 |
|
Jeff Thompson | 52843b1 | 2013-02-18 17:53:18 -0800 | [diff] [blame] | 208 | this.didOnStart = true;
|
| 209 |
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 210 | // Get the URI from the ContentObject including the version.
|
| 211 | var contentUriSpec;
|
| 212 | if (!this.uriEndsWithSegmentNumber && endsWithSegmentNumber(contentObject.name)) {
|
| 213 | var nameWithoutSegmentNumber = new Name
|
Jeff Thompson | 963d2da | 2012-12-02 23:31:22 -0800 | [diff] [blame] | 214 | (contentObject.name.components.slice(0, contentObject.name.components.length - 1));
|
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 215 | contentUriSpec = "ndn:" + nameWithoutSegmentNumber.to_uri();
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 216 | }
|
| 217 | else
|
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 218 | contentUriSpec = "ndn:" + contentObject.name.to_uri();
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 219 |
|
Jeff Thompson | 1eea632 | 2012-11-23 16:56:18 -0800 | [diff] [blame] | 220 | // Include the search and hash.
|
| 221 | contentUriSpec += this.uriSearchAndHash;
|
| 222 |
|
Jeff Thompson | e769c51 | 2012-11-04 17:25:07 -0800 | [diff] [blame] | 223 | var contentTypeEtc = getNameContentTypeAndCharset(contentObject.name);
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 224 | var ioService = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
|
| 225 | this.contentListener.onStart(contentTypeEtc.contentType, contentTypeEtc.contentCharset,
|
Jeff Thompson | 3663c67 | 2013-02-04 23:22:11 -0800 | [diff] [blame] | 226 | ioService.newURI(contentUriSpec, this.aURI.originCharset, null));
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 227 |
|
Jeff Thompson | 7fb08bf | 2013-03-15 00:13:10 -0700 | [diff] [blame] | 228 | if (segmentNumber == null) {
|
| 229 | // We are not doing segments, so just finish.
|
| 230 | this.contentListener.onReceivedContent(DataUtils.toString(contentObject.content));
|
Jeff Thompson | 74d38e3 | 2013-03-18 21:44:07 -0700 | [diff] [blame] | 231 | this.contentSha256.update(contentObject.content, contentObject.content.length);
|
Jeff Thompson | 7fb08bf | 2013-03-15 00:13:10 -0700 | [diff] [blame] | 232 | this.contentListener.onStop();
|
Jeff Thompson | f6995b5 | 2013-01-23 21:21:16 -0800 | [diff] [blame] | 233 |
|
Jeff Thompson | 7fb08bf | 2013-03-15 00:13:10 -0700 | [diff] [blame] | 234 | if (!this.uriEndsWithSegmentNumber) {
|
| 235 | var nameContentDigest = contentObject.name.getContentDigestValue();
|
Jeff Thompson | dd038fc | 2013-03-16 16:29:47 -0700 | [diff] [blame] | 236 | if (nameContentDigest != null && this.contentSha256 != null &&
|
Jeff Thompson | 74d38e3 | 2013-03-18 21:44:07 -0700 | [diff] [blame] | 237 | !DataUtils.arraysEqual(nameContentDigest,
|
| 238 | DataUtils.toNumbersFromString(this.contentSha256.finish(false))))
|
Jeff Thompson | 7fb08bf | 2013-03-15 00:13:10 -0700 | [diff] [blame] | 239 | // TODO: How to show the user an error for invalid digest?
|
Jeff Thompson | 74d38e3 | 2013-03-18 21:44:07 -0700 | [diff] [blame] | 240 | dump("Content does not match digest in name " + contentObject.name.to_uri() + "\n");
|
Jeff Thompson | 7fb08bf | 2013-03-15 00:13:10 -0700 | [diff] [blame] | 241 | }
|
| 242 | return Closure.RESULT_OK;
|
Jeff Thompson | f6995b5 | 2013-01-23 21:21:16 -0800 | [diff] [blame] | 243 | }
|
Jeff Thompson | 7fb08bf | 2013-03-15 00:13:10 -0700 | [diff] [blame] | 244 | else
|
| 245 | // We are doing segments. Make sure we always request the same base name.
|
| 246 | this.nameWithoutSegment = new Name(contentObject.name.components.slice
|
| 247 | (0, contentObject.name.components.length - 1));
|
Jeff Thompson | f6995b5 | 2013-01-23 21:21:16 -0800 | [diff] [blame] | 248 | }
|
| 249 |
|
Jeff Thompson | 7fb08bf | 2013-03-15 00:13:10 -0700 | [diff] [blame] | 250 | if (segmentNumber == null)
|
| 251 | // We should be doing segments at this point.
|
| 252 | return Closure.RESULT_ERR;
|
| 253 |
|
| 254 | if (!(contentObject.name.components.length == this.nameWithoutSegment.components.length + 1 &&
|
| 255 | this.nameWithoutSegment.match(contentObject.name)))
|
| 256 | // The content object name is not part of our sequence of segments.
|
| 257 | return Closure.RESULT_ERR;
|
| 258 |
|
| 259 | this.segmentStore.storeContent(segmentNumber, contentObject);
|
| 260 |
|
Jeff Thompson | f6995b5 | 2013-01-23 21:21:16 -0800 | [diff] [blame] | 261 | if (contentObject.signedInfo != null && contentObject.signedInfo.finalBlockID != null)
|
| 262 | this.finalSegmentNumber = DataUtils.bigEndianToUnsignedInt(contentObject.signedInfo.finalBlockID);
|
| 263 |
|
| 264 | // The content was already put in the store. Retrieve as much as possible.
|
| 265 | var entry;
|
| 266 | while ((entry = this.segmentStore.maybeRetrieveNextEntry()) != null) {
|
| 267 | segmentNumber = entry.key;
|
| 268 | contentObject = entry.value;
|
| 269 | this.contentListener.onReceivedContent(DataUtils.toString(contentObject.content));
|
Jeff Thompson | 74d38e3 | 2013-03-18 21:44:07 -0700 | [diff] [blame] | 270 | this.contentSha256.update(contentObject.content, contentObject.content.length);
|
Jeff Thompson | f6995b5 | 2013-01-23 21:21:16 -0800 | [diff] [blame] | 271 |
|
| 272 | if (this.finalSegmentNumber != null && segmentNumber == this.finalSegmentNumber) {
|
| 273 | // Finished.
|
| 274 | this.contentListener.onStop();
|
| 275 | var nameContentDigest = contentObject.name.getContentDigestValue();
|
Jeff Thompson | dd038fc | 2013-03-16 16:29:47 -0700 | [diff] [blame] | 276 | if (nameContentDigest != null && this.contentSha256 != null &&
|
Jeff Thompson | 74d38e3 | 2013-03-18 21:44:07 -0700 | [diff] [blame] | 277 | !DataUtils.arraysEqual(nameContentDigest,
|
| 278 | DataUtils.toNumbersFromString(this.contentSha256.finish(false))))
|
Jeff Thompson | f6995b5 | 2013-01-23 21:21:16 -0800 | [diff] [blame] | 279 | // TODO: How to show the user an error for invalid digest?
|
Jeff Thompson | 74d38e3 | 2013-03-18 21:44:07 -0700 | [diff] [blame] | 280 | dump("Content does not match digest in name " + contentObject.name.to_uri() + "\n");
|
Jeff Thompson | f6995b5 | 2013-01-23 21:21:16 -0800 | [diff] [blame] | 281 |
|
| 282 | return Closure.RESULT_OK;
|
| 283 | }
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 284 | }
|
| 285 |
|
Jeff Thompson | f6995b5 | 2013-01-23 21:21:16 -0800 | [diff] [blame] | 286 | if (this.finalSegmentNumber == null && !this.didRequestFinalSegment) {
|
Jeff Thompson | b083c8e | 2013-01-23 21:27:32 -0800 | [diff] [blame] | 287 | this.didRequestFinalSegment = true;
|
Jeff Thompson | f6995b5 | 2013-01-23 21:21:16 -0800 | [diff] [blame] | 288 | // Try to determine the final segment now.
|
Jeff Thompson | 4a4caba | 2013-02-28 21:31:33 -0800 | [diff] [blame] | 289 | // Clone the template to set the childSelector.
|
| 290 | var childSelectorTemplate = this.segmentTemplate.clone();
|
| 291 | childSelectorTemplate.childSelector = 1;
|
Jeff Thompson | 52843b1 | 2013-02-18 17:53:18 -0800 | [diff] [blame] | 292 | this.ndn.expressInterest
|
Jeff Thompson | 7fb08bf | 2013-03-15 00:13:10 -0700 | [diff] [blame] | 293 | (this.nameWithoutSegment, new ExponentialReExpressClosure(this), childSelectorTemplate);
|
Jeff Thompson | f6995b5 | 2013-01-23 21:21:16 -0800 | [diff] [blame] | 294 | }
|
| 295 |
|
| 296 | // Request new segments.
|
| 297 | var toRequest = this.segmentStore.requestSegmentNumbers(2);
|
| 298 | for (var i = 0; i < toRequest.length; ++i) {
|
| 299 | if (this.finalSegmentNumber != null && toRequest[i] > this.finalSegmentNumber)
|
| 300 | continue;
|
| 301 |
|
Jeff Thompson | 52843b1 | 2013-02-18 17:53:18 -0800 | [diff] [blame] | 302 | this.ndn.expressInterest
|
Jeff Thompson | 7fb08bf | 2013-03-15 00:13:10 -0700 | [diff] [blame] | 303 | (new Name(this.nameWithoutSegment).addSegment(toRequest[i]),
|
Jeff Thompson | ca2535c | 2013-02-28 22:26:13 -0800 | [diff] [blame] | 304 | new ExponentialReExpressClosure(this), this.segmentTemplate);
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 305 | }
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 306 |
|
| 307 | return Closure.RESULT_OK;
|
Jeff Thompson | f6995b5 | 2013-01-23 21:21:16 -0800 | [diff] [blame] | 308 | } catch (ex) {
|
| 309 | dump("ContentClosure.upcall exception: " + ex + "\n" + ex.stack);
|
| 310 | return Closure.RESULT_ERR;
|
| 311 | }
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 312 | };
|
Jeff Thompson | f6995b5 | 2013-01-23 21:21:16 -0800 | [diff] [blame] | 313 |
|
| 314 | /*
|
| 315 | * A SegmentStore stores segments until they are retrieved in order starting with segment 0.
|
| 316 | */
|
| 317 | var SegmentStore = function SegmentStore() {
|
| 318 | // Each entry is an object where the key is the segment number and value is null if
|
| 319 | // the segment number is requested or the contentObject if received.
|
| 320 | this.store = new SortedArray();
|
| 321 | this.maxRetrievedSegmentNumber = -1;
|
| 322 | };
|
| 323 |
|
| 324 | SegmentStore.prototype.storeContent = function(segmentNumber, contentObject) {
|
| 325 | // We don't expect to try to store a segment that has already been retrieved, but check anyway.
|
| 326 | if (segmentNumber > this.maxRetrievedSegmentNumber)
|
| 327 | this.store.set(segmentNumber, contentObject);
|
| 328 | };
|
| 329 |
|
| 330 | /*
|
| 331 | * If the min segment number is this.maxRetrievedSegmentNumber + 1 and its value is not null,
|
| 332 | * then delete from the store, return the entry with key and value, and update maxRetrievedSegmentNumber.
|
| 333 | * Otherwise return null.
|
| 334 | */
|
| 335 | SegmentStore.prototype.maybeRetrieveNextEntry = function() {
|
| 336 | if (this.store.entries.length > 0 && this.store.entries[0].value != null &&
|
| 337 | this.store.entries[0].key == this.maxRetrievedSegmentNumber + 1) {
|
| 338 | var entry = this.store.entries[0];
|
| 339 | this.store.removeAt(0);
|
| 340 | ++this.maxRetrievedSegmentNumber;
|
| 341 | return entry;
|
| 342 | }
|
| 343 | else
|
| 344 | return null;
|
| 345 | };
|
| 346 |
|
| 347 | /*
|
| 348 | * Return an array of the next segment numbers that need to be requested so that the total
|
| 349 | * requested segments is totalRequestedSegments. If a segment store entry value is null, it is
|
| 350 | * already requested and is not returned. If a segment number is returned, create a
|
| 351 | * entry in the segment store with a null value.
|
| 352 | */
|
| 353 | SegmentStore.prototype.requestSegmentNumbers = function(totalRequestedSegments) {
|
| 354 | // First, count how many are already requested.
|
| 355 | var nRequestedSegments = 0;
|
| 356 | for (var i = 0; i < this.store.entries.length; ++i) {
|
| 357 | if (this.store.entries[i].value == null) {
|
| 358 | ++nRequestedSegments;
|
| 359 | if (nRequestedSegments >= totalRequestedSegments)
|
| 360 | // Already maxed out on requests.
|
| 361 | return [];
|
| 362 | }
|
| 363 | }
|
| 364 |
|
| 365 | var toRequest = [];
|
| 366 | var nextSegmentNumber = this.maxRetrievedSegmentNumber + 1;
|
| 367 | for (var i = 0; i < this.store.entries.length; ++i) {
|
| 368 | var entry = this.store.entries[i];
|
| 369 | // Fill in the gap before the segment number in the entry.
|
| 370 | while (nextSegmentNumber < entry.key) {
|
| 371 | toRequest.push(nextSegmentNumber);
|
| 372 | ++nextSegmentNumber;
|
| 373 | ++nRequestedSegments;
|
| 374 | if (nRequestedSegments >= totalRequestedSegments)
|
| 375 | break;
|
| 376 | }
|
| 377 | if (nRequestedSegments >= totalRequestedSegments)
|
| 378 | break;
|
| 379 |
|
| 380 | nextSegmentNumber = entry.key + 1;
|
| 381 | }
|
| 382 |
|
| 383 | // We already filled in the gaps for the segments in the store. Continue after the last.
|
| 384 | while (nRequestedSegments < totalRequestedSegments) {
|
| 385 | toRequest.push(nextSegmentNumber);
|
| 386 | ++nextSegmentNumber;
|
| 387 | ++nRequestedSegments;
|
| 388 | }
|
| 389 |
|
| 390 | // Mark the new segment numbers as requested.
|
| 391 | for (var i = 0; i < toRequest.length; ++i)
|
| 392 | this.store.set(toRequest[i], null);
|
| 393 | return toRequest;
|
| 394 | }
|
| 395 |
|
| 396 | /*
|
| 397 | * A SortedArray is an array of objects with key and value, where the key is an integer.
|
| 398 | */
|
| 399 | var SortedArray = function SortedArray() {
|
| 400 | this.entries = [];
|
| 401 | }
|
| 402 |
|
| 403 | SortedArray.prototype.sortEntries = function() {
|
| 404 | this.entries.sort(function(a, b) { return a.key - b.key; });
|
| 405 | };
|
| 406 |
|
| 407 | SortedArray.prototype.indexOfKey = function(key) {
|
| 408 | for (var i = 0; i < this.entries.length; ++i) {
|
| 409 | if (this.entries[i].key == key)
|
| 410 | return i;
|
| 411 | }
|
| 412 |
|
| 413 | return -1;
|
| 414 | }
|
| 415 |
|
| 416 | SortedArray.prototype.set = function(key, value) {
|
| 417 | var i = this.indexOfKey(key);
|
| 418 | if (i >= 0) {
|
| 419 | this.entries[i].value = value;
|
| 420 | return;
|
| 421 | }
|
| 422 |
|
| 423 | this.entries.push({ key: key, value: value});
|
| 424 | this.sortEntries();
|
| 425 | }
|
| 426 |
|
| 427 | SortedArray.prototype.removeAt = function(index) {
|
| 428 | this.entries.splice(index, 1);
|
| 429 | }
|
| 430 |
|
Jeff Thompson | df0a6f7 | 2012-10-21 15:58:58 -0700 | [diff] [blame] | 431 | /*
|
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 432 | * Scan the name from the last component to the first (skipping special name components)
|
Jeff Thompson | 25b0641 | 2012-10-21 20:07:57 -0700 | [diff] [blame] | 433 | * for a recognized file name extension, and return an object with properties contentType and charset.
|
Jeff Thompson | df0a6f7 | 2012-10-21 15:58:58 -0700 | [diff] [blame] | 434 | */
|
Jeff Thompson | e769c51 | 2012-11-04 17:25:07 -0800 | [diff] [blame] | 435 | function getNameContentTypeAndCharset(name) {
|
Jeff Thompson | 16a35f7 | 2012-11-25 08:07:33 -0800 | [diff] [blame] | 436 | var iFileName = name.indexOfFileName();
|
| 437 | if (iFileName < 0)
|
| 438 | // Get the default mime type.
|
| 439 | return MimeTypes.getContentTypeAndCharset("");
|
Jeff Thompson | df0a6f7 | 2012-10-21 15:58:58 -0700 | [diff] [blame] | 440 |
|
Jeff Thompson | 16a35f7 | 2012-11-25 08:07:33 -0800 | [diff] [blame] | 441 | return MimeTypes.getContentTypeAndCharset
|
| 442 | (DataUtils.toString(name.components[iFileName]).toLowerCase());
|
Jeff Thompson | df0a6f7 | 2012-10-21 15:58:58 -0700 | [diff] [blame] | 443 | }
|
Jeff Thompson | 10de459 | 2012-10-21 23:54:18 -0700 | [diff] [blame] | 444 |
|
| 445 | /*
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 446 | * Return true if the last component in the name is a segment number..
|
Jeff Thompson | 10de459 | 2012-10-21 23:54:18 -0700 | [diff] [blame] | 447 | */
|
Jeff Thompson | 9e6dff0 | 2012-11-04 09:20:47 -0800 | [diff] [blame] | 448 | function endsWithSegmentNumber(name) {
|
Jeff Thompson | 10de459 | 2012-10-21 23:54:18 -0700 | [diff] [blame] | 449 | return name.components != null && name.components.length >= 1 &&
|
| 450 | name.components[name.components.length - 1].length >= 1 &&
|
| 451 | name.components[name.components.length - 1][0] == 0;
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 452 | }
|
| 453 |
|
| 454 | /*
|
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 455 | * Find all search keys starting with "ndn." and set the attribute in template.
|
| 456 | * Return the search string including the starting "?" but with the "ndn." keys removed,
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 457 | * or return "" if there are no search terms left.
|
| 458 | */
|
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 459 | function extractNdnSearch(search, template) {
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 460 | if (!(search.length >= 1 && search[0] == '?'))
|
| 461 | return search;
|
| 462 |
|
| 463 | var terms = search.substr(1).split('&');
|
| 464 | var i = 0;
|
| 465 | while (i < terms.length) {
|
| 466 | var keyValue = terms[i].split('=');
|
| 467 | var key = keyValue[0].trim();
|
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 468 | if (key.substr(0, 4) == "ndn.") {
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 469 | if (keyValue.length >= 1) {
|
Jeff Thompson | 754652d | 2012-11-24 16:23:43 -0800 | [diff] [blame] | 470 | var value = keyValue[1].trim();
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 471 | var nonNegativeInt = parseInt(value);
|
| 472 |
|
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 473 | if (key == "ndn.MinSuffixComponents" && nonNegativeInt >= 0)
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 474 | template.minSuffixComponents = nonNegativeInt;
|
Jeff Thompson | 6ac75d2 | 2013-02-04 22:41:34 -0800 | [diff] [blame] | 475 | else if (key == "ndn.MaxSuffixComponents" && nonNegativeInt >= 0)
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 476 | template.maxSuffixComponents = nonNegativeInt;
|
Jeff Thompson | 6ac75d2 | 2013-02-04 22:41:34 -0800 | [diff] [blame] | 477 | else if (key == "ndn.ChildSelector" && nonNegativeInt >= 0)
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 478 | template.childSelector = nonNegativeInt;
|
Jeff Thompson | 6ac75d2 | 2013-02-04 22:41:34 -0800 | [diff] [blame] | 479 | else if (key == "ndn.AnswerOriginKind" && nonNegativeInt >= 0)
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 480 | template.answerOriginKind = nonNegativeInt;
|
Jeff Thompson | 6ac75d2 | 2013-02-04 22:41:34 -0800 | [diff] [blame] | 481 | else if (key == "ndn.Scope" && nonNegativeInt >= 0)
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 482 | template.scope = nonNegativeInt;
|
Jeff Thompson | 6ac75d2 | 2013-02-04 22:41:34 -0800 | [diff] [blame] | 483 | else if (key == "ndn.InterestLifetime" && nonNegativeInt >= 0)
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 484 | template.interestLifetime = nonNegativeInt;
|
Jeff Thompson | 6ac75d2 | 2013-02-04 22:41:34 -0800 | [diff] [blame] | 485 | else if (key == "ndn.PublisherPublicKeyDigest")
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 486 | template.publisherPublicKeyDigest = DataUtils.toNumbersFromString(unescape(value));
|
Jeff Thompson | 6ac75d2 | 2013-02-04 22:41:34 -0800 | [diff] [blame] | 487 | else if (key == "ndn.Nonce")
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 488 | template.nonce = DataUtils.toNumbersFromString(unescape(value));
|
Jeff Thompson | 6ac75d2 | 2013-02-04 22:41:34 -0800 | [diff] [blame] | 489 | else if (key == "ndn.Exclude")
|
| 490 | template.exclude = parseExclude(value);
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 491 | }
|
| 492 |
|
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 493 | // Remove the "ndn." term and don't advance i.
|
Jeff Thompson | 5fc9b67 | 2012-11-24 10:00:56 -0800 | [diff] [blame] | 494 | terms.splice(i, 1);
|
| 495 | }
|
| 496 | else
|
| 497 | ++i;
|
| 498 | }
|
| 499 |
|
| 500 | if (terms.length == 0)
|
| 501 | return "";
|
| 502 | else
|
| 503 | return "?" + terms.join('&');
|
Jeff Thompson | 963d2da | 2012-12-02 23:31:22 -0800 | [diff] [blame] | 504 | }
|
Jeff Thompson | 6ac75d2 | 2013-02-04 22:41:34 -0800 | [diff] [blame] | 505 |
|
| 506 | /*
|
| 507 | * Parse the comma-separated list of exclude components and return an Exclude.
|
| 508 | */
|
| 509 | function parseExclude(value) {
|
| 510 | var excludeValues = [];
|
| 511 |
|
| 512 | var splitValue = value.split(',');
|
| 513 | for (var i = 0; i < splitValue.length; ++i) {
|
| 514 | var element = splitValue[i].trim();
|
| 515 | if (element == "*")
|
Jeff Thompson | 4a4caba | 2013-02-28 21:31:33 -0800 | [diff] [blame] | 516 | excludeValues.push(Exclude.ANY)
|
Jeff Thompson | 6ac75d2 | 2013-02-04 22:41:34 -0800 | [diff] [blame] | 517 | else
|
| 518 | excludeValues.push(Name.fromEscapedString(element));
|
| 519 | }
|
| 520 |
|
| 521 | return new Exclude(excludeValues);
|
| 522 | }
|
Jeff Thompson | 4a4caba | 2013-02-28 21:31:33 -0800 | [diff] [blame] | 523 |
|
| 524 | /*
|
| 525 | * Return the index of the first compoment that starts with %C1.META, or -1 if not found.
|
| 526 | */
|
| 527 | function getIndexOfMetaComponent(name) {
|
| 528 | for (var i = 0; i < name.components.length; ++i) {
|
| 529 | var component = name.components[i];
|
| 530 | if (component.length >= MetaComponentPrefix.length &&
|
| 531 | DataUtils.arraysEqual(component.subarray(0, MetaComponentPrefix.length),
|
| 532 | MetaComponentPrefix))
|
| 533 | return i;
|
| 534 | }
|
| 535 |
|
| 536 | return -1;
|
| 537 | }
|
| 538 |
|
| 539 | var MetaComponentPrefix = new Uint8Array([0xc1, 0x2e, 0x4d, 0x45, 0x54, 0x41]);
|