Skip to content

Commit

Permalink
added method setUserCredentials to xmlrpc_client, as parent lib does;
Browse files Browse the repository at this point in the history
added support for the <ex:nil/> from the apache library, both in input and output (output regulated by the xmlrpc_null_apache_encoding variable, input by the xmlrpc_null_extension one);
base64_decode now trims whitespace 

git-svn-id: https://svn.code.sf.net/p/phpxmlrpc/code/trunk/javascript@58 013ecfd8-0664-425d-a759-9c98391dc3f9
  • Loading branch information
ggiunta committed Sep 5, 2009
1 parent 5755b35 commit 30f9a38
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
8 changes: 8 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
2009/09/05 - G. Giunta (giunta.gaetano@gmail.com)

* xmlrpc_lib.js: added method setUserCredentials to xmlrpc_client, as parent lib does;
added support for the <ex:nil/> from the apache library, both in input and output
(output regulated by the xmlrpc_null_apache_encoding variable, input by the
xmlrpc_null_extension one);
base64_decode now trims whitespace

2008/03/07 - G. Giunta (giunta.gaetano@gmail.com)

* improve Makefile for windows xp
Expand Down
39 changes: 35 additions & 4 deletions lib/xmlrpc_lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ var xmlrpcName = 'XML-RPC for JAVASCRIPT';
* Library version number. Used in the client's httprequests to identify self to server
* @type string
*/
var xmlrpcVersion = '0.3';
var xmlrpcVersion = '0.4';

// let user errors start at 800
var xmlrpcerruser = 800;
Expand All @@ -121,6 +121,11 @@ var xmlrpcstr = {
no_parser: 'no support for parsing xml compiled in'
}

// set to TRUE to enable correct decoding of <NIL/> and <EX:NIL/> values
var xmlrpc_null_extension = false;
// set to TRUE to enable encoding of php NULL values to <EX:NIL/> instead of <NIL/>
var xmlrpc_null_apache_encoding = false;

var _xh = null;

// Please note that MS says you should only use versions 6 and 3...
Expand Down Expand Up @@ -174,7 +179,7 @@ function xmlrpc_client (path, server, port, method)
this.polling_interval = 50;
this.polling_queue = [];
this.tid = 0;

this.user_agent = xmlrpcName + ' ' + xmlrpcVersion;
this.init(path, server, port, method);
}

Expand Down Expand Up @@ -280,6 +285,16 @@ xmlrpc_client.prototype.setCredentials = function (username, password, authtype)
//}
}

/**
* Set user-agent string that will be used by this client instance
* in http headers sent to the server
* @param {string} agentstring
* @public
*/
xmlrpc_client.prototype.setUserAgent = function(agentstring)
{
this.user_agent = agentstring;
}
/**
* Send an xmlrpc request.
*
Expand Down Expand Up @@ -410,7 +425,7 @@ xmlrpc_client.prototype.send = function (msg, timeout, method)

/// @todo add support for setting cookies by hand

httpconn.setRequestHeader('User-Agent', xmlrpcName + ' ' + xmlrpcVersion);
httpconn.setRequestHeader('User-Agent', user_agent);
httpconn.setRequestHeader('Content-type', msg.content_type);
if (!this.keepalive)
{
Expand Down Expand Up @@ -1049,7 +1064,14 @@ xmlrpcval.prototype.serialize = function (charset_encoding)
var result = '<base64>'+base64_encode(this.me)+'</base64>';
break;
case 9:
var result = '<nil/>';
if (xmlrpc_null_apache_encoding)
{
var result = '<ex:nil/>';
}
else
{
var result = '<nil/>';
}
break;
case 2:
var result = '<array>\n<data>\n';
Expand Down Expand Up @@ -2224,6 +2246,7 @@ function xmlrpc_decode_xml(xml_val, options) {
* @public
*/
function base64_decode (aString) {
aString = aString.replace(/^\s+|\s+$/g, "");
if ((aString.length % 4) == 0)
{
if (typeof atob == 'function')
Expand Down Expand Up @@ -2627,6 +2650,14 @@ function parseXmlrpcValue(node, return_jsvals)
}
}
break;
case 'nil':
case 'ex:nil':
if (xmlrpc_null_extension)
{
ret = null;
break;
}
// fall through voluntarily
default:
throw 'Found incorrect element inside \'value\' :'+ child.tagName;

Expand Down

0 comments on commit 30f9a38

Please sign in to comment.