Added Closure.js. Put expressInterest in NDN.js. Use it in ccnxProtocolService.js.
diff --git a/js/ccnxProtocol/components/ccnxProtocolService.js b/js/ccnxProtocol/components/ccnxProtocolService.js
index 2bf369b..c7d4d1e 100644
--- a/js/ccnxProtocol/components/ccnxProtocolService.js
+++ b/js/ccnxProtocol/components/ccnxProtocolService.js
@@ -35,50 +35,58 @@
{
try {
var requestContent = function(contentListener) {
- var interest = aURI.spec.split(":")[1];
+ var name = aURI.spec.split(":")[1];
// 131.179.141.18 is lioncub.metwi.ucla.edu .
var ndn = new NDN('131.179.141.18');
- var coListener = {
- onReceivedContentObject : function(contentObject) {
- // Set up defaults.
- var content = "";
- var contentType = "text/html";
- var contentCharset = "utf-8";
+ var ContentClosure = function ContentClosure() {
+ // Inherit from Closure.
+ Closure.call(this);
+ }
+ ContentClosure.prototype.upcall = function(kind, upcallInfo) {
+ if (!(kind == Closure.UPCALL_CONTENT ||
+ kind == Closure.UPCALL_CONTENT_UNVERIFIED))
+ // The upcall is not for us.
+ return;
+
+ var contentObject = upcallInfo.contentObject;
+
+ // Set up defaults.
+ var content = "";
+ var contentType = "text/html";
+ var contentCharset = "utf-8";
- // TODO: Need to check the signature, confirm that the name matches, etc.
- if (contentObject.content != null) {
- content = DataUtils.toString(contentObject.content);
+ if (contentObject.content != null) {
+ content = DataUtils.toString(contentObject.content);
- // TODO: Should look at the returned Name to get contentType. For now,
- // just look for a file extension in the original interest.
- var interestLowerCase = interest.toLowerCase();
- if (interestLowerCase.indexOf(".gif") >= 0) {
- contentType = "image/gif";
- contentCharset = "ISO-8859-1";
- }
- else if (interestLowerCase.indexOf(".jpg") >= 0 ||
- interestLowerCase.indexOf(".jpeg") >= 0) {
- contentType = "image/jpeg";
- contentCharset = "ISO-8859-1";
- }
- else if (interestLowerCase.indexOf(".png") >= 0) {
- contentType = "image/png";
- contentCharset = "ISO-8859-1";
- }
- else if (interestLowerCase.indexOf(".bmp") >= 0) {
- contentType = "image/bmp";
- contentCharset = "ISO-8859-1";
- }
- else if (interestLowerCase.indexOf(".css") >= 0)
- contentType = "text/css";
+ // TODO: Should look at the returned Name to get contentType. For now,
+ // just look for a file extension in the original name.
+ var nameLowerCase = name.toLowerCase();
+ if (nameLowerCase.indexOf(".gif") >= 0) {
+ contentType = "image/gif";
+ contentCharset = "ISO-8859-1";
}
-
- contentListener.onReceivedContent(content, contentType, contentCharset);
+ else if (nameLowerCase.indexOf(".jpg") >= 0 ||
+ nameLowerCase.indexOf(".jpeg") >= 0) {
+ contentType = "image/jpeg";
+ contentCharset = "ISO-8859-1";
+ }
+ else if (nameLowerCase.indexOf(".png") >= 0) {
+ contentType = "image/png";
+ contentCharset = "ISO-8859-1";
+ }
+ else if (nameLowerCase.indexOf(".bmp") >= 0) {
+ contentType = "image/bmp";
+ contentCharset = "ISO-8859-1";
+ }
+ else if (nameLowerCase.indexOf(".css") >= 0)
+ contentType = "text/css";
}
+
+ contentListener.onReceivedContent(content, contentType, contentCharset);
};
- ndn.getAsync(interest, coListener);
+ ndn.expressInterest(new Name(name), new ContentClosure());
};
return new ContentChannel(aURI, requestContent);