Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/bandwagon/content/scripts/rpc/net.js
diff options
context:
space:
mode:
Diffstat (limited to 'bandwagon/content/scripts/rpc/net.js')
-rw-r--r--bandwagon/content/scripts/rpc/net.js81
1 files changed, 34 insertions, 47 deletions
diff --git a/bandwagon/content/scripts/rpc/net.js b/bandwagon/content/scripts/rpc/net.js
index 7a2c2a8..21b7475 100644
--- a/bandwagon/content/scripts/rpc/net.js
+++ b/bandwagon/content/scripts/rpc/net.js
@@ -53,11 +53,18 @@ Bandwagon.RPC.Net = function(Bandwagon, Components)
this._queryString = '';
this._postData = '';
this._type = null;
- this._headers = {};
this._request = null;
this._logger = null;
+ /*
+ this.release = function() {
+ this._request = null;
+ this.onComplete = null;
+ this.logger = null;
+ }
+ */
+
this.finished = function(result, response, request)
{
this._logger.debug('Bandwagon.RPC.Net.finished: ' + this.id + ': finished');
@@ -65,11 +72,11 @@ Bandwagon.RPC.Net = function(Bandwagon, Components)
this.onComplete(this, result, response, this._type, request);
};
- this.failed = function(errorCode, errorMessage, data)
+ this.failed = function(errorCode, errorMessage)
{
this._logger.debug('Bandwagon.RPC.Net.failed: ' + this.id + ': failed');
this.status = this.Bandwagon.RPC.Constants.BANDWAGON_RPC_NET_FINISHED;
- var response = {errorCode: errorCode, errorMessage: errorMessage, data: data};
+ var response = {errorCode: errorCode, errorMessage: errorMessage};
this.onComplete(this, this.Bandwagon.RPC.Constants.BANDWAGON_RPC_NET_FAILURE, response, this._type, null);
};
@@ -107,15 +114,14 @@ Bandwagon.RPC.Net = function(Bandwagon, Components)
try
{
+ // parse xml here instead, put in response var
var xmlStr = rpcnetrequest.responseText;
- // dave@briks: The following hacks are workarounds for E4X
- // bugs/features. If anyone knows the dark secrets of namespace
- // support in e4x please let me know!
-
+ // workaround for E4X bugs/features
xmlStr = xmlStr.replace(/^<\?xml\s+version\s*=\s*(["'])[^\1]+\1[^?]*\?>/, ""); // bug 336551
- xmlStr = xmlStr.replace(/xmlns="http:\/\/addons.mozilla.org\/"/gi, "");
- xmlStr = xmlStr.replace(/xml:base=/gi, "xmlbase=");
+
+ //default xml namespace = 'http://addons.mozilla.org/';
+ xmlStr = xmlStr.replace(/xmlns="http:\/\/addons.mozilla.org\/"/, "");
response = new XML(xmlStr);
@@ -145,7 +151,7 @@ Bandwagon.RPC.Net = function(Bandwagon, Components)
else
{
// application error (bad xml)
- rpcnet.failed(rpcnet.Bandwagon.RPC.Constants.BANDWAGON_RPC_SERVICE_ERROR_BAD_XML, lastErr, response);
+ rpcnet.failed(rpcnet.Bandwagon.RPC.Constants.BANDWAGON_RPC_SERVICE_ERROR_BAD_XML, lastErr);
return;
}
}
@@ -154,53 +160,54 @@ Bandwagon.RPC.Net = function(Bandwagon, Components)
try
{
- lastErr = (response.attribute("reason")?response.attribute("reason"):"?");
+ // TODO what form does bandwagon rpc error take?
+ lastErr = response.message;
rpcnet._logger.debug('Bandwagon.RPC.Net.send.onreadystatechange: ' + rpcnet.id + ": completed, response error message = '" + lastErr + "'");
}
catch (e)
{
- rpcnet._logger.debug('Bandwagon.RPC.Net.send.onreadystatechange: ' + rpcnet.id + ": have an error status code (" + status + "), but there is no error message in the XML response");
+ rpcnet._logger.debug('Bandwagon.RPC.Net.send.onreadystatechange: ' + rpcnet.id + ": have an error status code, but there is no error message in the XML response");
lastErr = null;
}
if (status == 400)
{
- rpcnet.failed(rpcnet.Bandwagon.RPC.Constants.BANDWAGON_RPC_SERVICE_ERROR_BAD_REQUEST, lastErr, response);
+ rpcnet.failed(rpcnet.Bandwagon.RPC.Constants.BANDWAGON_RPC_SERVICE_ERROR_BAD_REQUEST, lastErr);
return;
}
else if (status == 401)
{
- rpcnet.failed(rpcnet.Bandwagon.RPC.Constants.BANDWAGON_RPC_SERVICE_ERROR_UNAUTHORIZED, lastErr, response);
+ rpcnet.failed(rpcnet.Bandwagon.RPC.Constants.BANDWAGON_RPC_SERVICE_ERROR_UNAUTHORIZED, lastErr);
return;
}
- else if (status == 403)
+ else if (status == 403)
{
- rpcnet.failed(rpcnet.Bandwagon.RPC.Constants.BANDWAGON_RPC_SERVICE_ERROR_FORBIDDEN, lastErr, response);
+ rpcnet.failed(rpcnet.Bandwagon.RPC.Constants.BANDWAGON_RPC_SERVICE_ERROR_FORBIDDEN, lastErr);
return;
}
else if (status == 404)
{
- rpcnet.failed(rpcnet.Bandwagon.RPC.Constants.BANDWAGON_RPC_SERVICE_ERROR_NOT_FOUND, lastErr, response);
+ rpcnet.failed(rpcnet.Bandwagon.RPC.Constants.BANDWAGON_RPC_SERVICE_ERROR_NOT_FOUND, lastErr);
return;
}
else if (status == 409)
{
- rpcnet.failed(rpcnet.Bandwagon.RPC.Constants.BANDWAGON_RPC_SERVICE_ERROR_CONFLICT, lastErr, response);
+ rpcnet.failed(rpcnet.Bandwagon.RPC.Constants.BANDWAGON_RPC_SERVICE_ERROR_CONFLICT, lastErr);
return;
}
else if (status == 422)
{
- rpcnet.failed(rpcnet.Bandwagon.RPC.Constants.BANDWAGON_RPC_SERVICE_ERROR_BAD_CONTEXT, lastErr, response);
+ rpcnet.failed(rpcnet.Bandwagon.RPC.Constants.BANDWAGON_RPC_SERVICE_ERROR_BAD_CONTEXT, lastErr);
return;
}
else if (status == 500)
{
- rpcnet.failed(rpcnet.Bandwagon.RPC.Constants.BANDWAGON_RPC_SERVICE_ERROR_INTERNAL_SERVER_ERROR, lastErr, response);
+ rpcnet.failed(rpcnet.Bandwagon.RPC.Constants.BANDWAGON_RPC_SERVICE_ERROR_INTERNAL_SERVER_ERROR, lastErr);
return;
}
else
{
- rpcnet.failed(rpcnet.Bandwagon.RPC.Constants.BANDWAGON_RPC_SERVICE_ERROR_CRITICAL_ERROR, lastErr, response);
+ rpcnet.failed(rpcnet.Bandwagon.RPC.Constants.BANDWAGON_RPC_SERVICE_ERROR_CRITICAL_ERROR, lastErr);
return;
}
};
@@ -227,7 +234,7 @@ Bandwagon.RPC.Net.prototype.setPostData = function(args)
for (var i in args)
{
- this._postData += this.Bandwagon.Util.encodeURL(i) + '=' + this.Bandwagon.Util.encodeURL(args[i]) + '&';
+ this._postData += encodeURIComponent(i) + '=' + encodeURIComponent(args[i]) + '&';
}
if ('&' == this._postData.charAt(this._postData.length-1))
@@ -242,7 +249,7 @@ Bandwagon.RPC.Net.prototype.setArguments = function(args)
for (var i in args)
{
- this._queryString += this.Bandwagon.Util.encodeURL(i) + '=' + this.Bandwagon.Util.encodeURL(args[i]) + '&';
+ this._queryString += encodeURIComponent(i) + '=' + encodeURIComponent(args[i]) + '&';
}
if ('&' == this._queryString.charAt(this._queryString.length-1))
@@ -261,10 +268,6 @@ Bandwagon.RPC.Net.prototype.setMethod = function(method)
{
this._method = 'DELETE';
}
- else if (method == 'PUT')
- {
- this._method = 'PUT';
- }
else
{
this._method = 'GET';
@@ -273,11 +276,6 @@ Bandwagon.RPC.Net.prototype.setMethod = function(method)
this._method = method;
}
-Bandwagon.RPC.Net.prototype.setHeader = function(header, value)
-{
- this._headers[header] = value;
-}
-
Bandwagon.RPC.Net.prototype.setCredentials = function(username, password)
{
this._basicAuthUsername = username;
@@ -296,18 +294,12 @@ Bandwagon.RPC.Net.prototype.send = function()
if (!rpcnetrequest) { rpcnet.failed(rpcnet.Bandwagon.RPC.Constants.BANDWAGON_RPC_NET_ERROR_XHR_CREATE); }
- rpcnetrequest.mozBackgroundRequest = true;
-
var postData = null;
var url = rpcnet._url;
- if (('POST' == rpcnet._method || 'PUT' == rpcnet._method)
- && rpcnet._postData.length > 0)
- {
+ if ('POST' == rpcnet._method && rpcnet._postData.length > 0) {
postData = rpcnet._postData;
- }
- else if (rpcnet._queryString && (rpcnet._queryString.length > 0))
- {
+ } else if (rpcnet._queryString && (rpcnet._queryString.length > 0)) {
url += "?" + rpcnet._queryString;
}
@@ -329,16 +321,11 @@ Bandwagon.RPC.Net.prototype.send = function()
rpcnetrequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
}
- for (var header in rpcnet._headers)
- {
- //rpcnet._logger.debug('Bandwagon.RPC.Net.send: ' + rpcnet.id + ': adding custom header ' + header + ': ' + rpcnet._headers[header]);
- rpcnetrequest.setRequestHeader(header, rpcnet._headers[header]);
- }
-
+ /* not needed for now
if ('' != rpcnet._basicAuthUsername) {
- rpcnet._logger.debug('Bandwagon.RPC.Net.send: using credentials for ' + rpcnet._basicAuthUsername);
rpcnetrequest.setRequestHeader('Authorization', 'Basic ' + btoa(rpcnet._basicAuthUsername + ':' + rpcnet._basicAuthPassword));
}
+ */
rpcnetrequest.setRequestHeader("If-Modified-Since", "Sat, 1 Jan 2005 00:00:00 GMT");