You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shindig.apache.org by et...@apache.org on 2008/02/20 00:10:06 UTC
svn commit: r629266 - in /incubator/shindig/trunk: config/syndicator.js
features/rpc/feature.xml features/rpc/rpc.js features/setprefs/setprefs.js
javascript/container/sample-rpc.html
Author: etnu
Date: Tue Feb 19 15:10:04 2008
New Revision: 629266
URL: http://svn.apache.org/viewvc?rev=629266&view=rev
Log:
Provided a legacy IFPC wire format layer to ensure that existing sites using IFPC can still handle requests from gadgets rendered on a shindig host. Currently this is only for gadget to container calls since shindig does not yet implement any container to gadget calls.
To use this, specify "useLegacyProtocol : true" for the rpc feature in your syndicator configuration.
Also fixed a bug in setprefs; it was not sending all parameters correctly.
Modified:
incubator/shindig/trunk/config/syndicator.js
incubator/shindig/trunk/features/rpc/feature.xml
incubator/shindig/trunk/features/rpc/rpc.js
incubator/shindig/trunk/features/setprefs/setprefs.js
incubator/shindig/trunk/javascript/container/sample-rpc.html
Modified: incubator/shindig/trunk/config/syndicator.js
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/config/syndicator.js?rev=629266&r1=629265&r2=629266&view=diff
==============================================================================
--- incubator/shindig/trunk/config/syndicator.js (original)
+++ incubator/shindig/trunk/config/syndicator.js Tue Feb 19 15:10:04 2008
@@ -66,6 +66,7 @@
"rpc" : {
// This should never be on the same host in a production environment!
// Only use this for TESTING!
- "parentRelayUrl" : "files/container/rpc_relay.html",
+ "parentRelayUrl" : "files/container/ifpc_relay.html",
+ "useLegacyProtocol" : false,
},
}}
Modified: incubator/shindig/trunk/features/rpc/feature.xml
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/features/rpc/feature.xml?rev=629266&r1=629265&r2=629266&view=diff
==============================================================================
--- incubator/shindig/trunk/features/rpc/feature.xml (original)
+++ incubator/shindig/trunk/features/rpc/feature.xml Tue Feb 19 15:10:04 2008
@@ -21,6 +21,11 @@
Required config:
parentRelayUrl: The url of the relay file for this service.
+
+Optional config:
+
+useLegacyProtocol: Boolean
+(if true, all calls to rpc.call will use the same wire format as ifpc).
-->
<name>rpc</name>
<gadget>
Modified: incubator/shindig/trunk/features/rpc/rpc.js
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/features/rpc/rpc.js?rev=629266&r1=629265&r2=629266&view=diff
==============================================================================
--- incubator/shindig/trunk/features/rpc/rpc.js (original)
+++ incubator/shindig/trunk/features/rpc/rpc.js Tue Feb 19 15:10:04 2008
@@ -32,6 +32,7 @@
var services = {};
var iframePool = [];
var relayUrl = {};
+ var useLegacyProtocol = {};
var callId = 0;
var callbacks = {};
@@ -61,6 +62,21 @@
};
/**
+ * Encodes arguments for the legacy IFPC wire format.
+ *
+ * @param {Object} args
+ * @return {String} the encoded args
+ */
+ function encodeLegacyData(args) {
+ var stringify = gadgets.json.stringify;
+ var argsEscaped = [];
+ for(var i = 0, j = args.length; i < j; ++i) {
+ argsEscaped.push(encodeURIComponent(stringify(args[i])));
+ }
+ return argsEscaped.join('&');
+ }
+
+ /**
* Helper function to process an RPC request
* @param {Object} rpc RPC request object
* @private
@@ -121,6 +137,7 @@
*/
function init(config) {
relayUrl['..'] = config.rpc.parentRelayUrl;
+ useLegacyProtocol['..'] = !!config.rpc.useLegacyProtocol;
}
var requiredConfig = {
@@ -194,16 +211,8 @@
from = window.name;
} else {
from = '..';
- targetId = idFormat.replace(/%targetId%/g, targetId);
}
- var rpcData = gadgets.json.stringify({
- s: serviceName,
- f: from,
- c: callback ? callId : 0,
- a: Array.prototype.slice.call(arguments, 3)
- });
-
switch (relayChannel) {
case 'dpm': // use document.postMessage
var targetDoc = targetId === '..' ? parent.document :
@@ -216,11 +225,26 @@
break;
default: // use 'ifpc' as a fallback mechanism
var relay = gadgets.rpc.getRelayUrl(targetId);
- // IFrame packet format:
- // # targetId & sourceId@callId & packetNum & packetId & packetData
+
// TODO split message if too long
- var src = [relay, '#', targetId, '&', from, '@', callId,
- '&1&0&', rpcData].join('');
+ var src;
+ if (useLegacyProtocol[targetId]) {
+ // #iframe_id&callId&num_packets&packet_num&block_of_data
+ var legacyData = [from, serviceName, null, null, from].concat(
+ Array.prototype.slice.call(arguments, 3));
+ src = [relay, '#', encodeLegacyData([from, '&', callId, '&1&0&',
+ encodeLegacyData(legacyData)])].join('');
+ } else {
+ var rpcData = gadgets.json.stringify({
+ s: serviceName,
+ f: from,
+ c: callback ? callId : 0,
+ a: Array.prototype.slice.call(arguments, 3)
+ });
+ // # targetId & sourceId@callId & packetNum & packetId & packetData
+ src = [relay, '#', targetId, '&', from, '@', callId,
+ '&1&0&', rpcData].join('');
+ }
emitInvisibleIframe(src);
}
},
Modified: incubator/shindig/trunk/features/setprefs/setprefs.js
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/features/setprefs/setprefs.js?rev=629266&r1=629265&r2=629266&view=diff
==============================================================================
--- incubator/shindig/trunk/features/setprefs/setprefs.js (original)
+++ incubator/shindig/trunk/features/setprefs/setprefs.js Tue Feb 19 15:10:04 2008
@@ -45,10 +45,9 @@
var args = [
null, // go to parent
"set_pref", // service name
- null // no callback
- ];
- // and add the other params...
- args.concat(Array.prototype.slice.call(arguments));
+ null, // no callback
+ gadgets.util.getUrlParameters().ifpctok || 0 // Legacy IFPC "security".
+ ].concat(Array.prototype.slice.call(arguments));
gadgets.rpc.call.apply(gadgets.rpc, args);
};
Modified: incubator/shindig/trunk/javascript/container/sample-rpc.html
URL: http://svn.apache.org/viewvc/incubator/shindig/trunk/javascript/container/sample-rpc.html?rev=629266&r1=629265&r2=629266&view=diff
==============================================================================
--- incubator/shindig/trunk/javascript/container/sample-rpc.html (original)
+++ incubator/shindig/trunk/javascript/container/sample-rpc.html Tue Feb 19 15:10:04 2008
@@ -25,6 +25,7 @@
<script src="../../js/core.js?c=1"></script>
<body>
<script>
+ gadgets.ifpc_.registerService("set_pref", onSetPref);
function makeXhr() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
@@ -56,7 +57,7 @@
newGadget.innerHTML = ["Unable to process gadget: ", gadget.url, ". Errors: <pre>", gadget.errors.join("\n"), "</pre>"].join("");
} else {
newGadget.innerHTML = ['<h2>', gadget.title, '</h2>',
- '<iframe src="', gadget.content, '&libs=', libs ,'" id="remote_iframe_', gadget.moduleId, '"></iframe>'
+ '<iframe src="', gadget.content, '&libs=', libs ,'" id="remote_iframe_', gadget.moduleId, '" name="remote_iframe_', gadget.moduleId, '"></iframe>'
].join("");
}
newGadget.className = "gadget";