From 30f9a3820b5464fbd7f48ac2a76724a59cf9aba0 Mon Sep 17 00:00:00 2001 From: ggiunta Date: Sat, 5 Sep 2009 16:53:52 +0000 Subject: [PATCH] added method setUserCredentials to xmlrpc_client, as parent lib does; added support for the 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 --- Changelog.txt | 8 ++++++++ lib/xmlrpc_lib.js | 39 +++++++++++++++++++++++++++++++++++---- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index ea4acc8..4f77288 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -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 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 diff --git a/lib/xmlrpc_lib.js b/lib/xmlrpc_lib.js index bedf0d4..4c7bff2 100644 --- a/lib/xmlrpc_lib.js +++ b/lib/xmlrpc_lib.js @@ -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; @@ -121,6 +121,11 @@ var xmlrpcstr = { no_parser: 'no support for parsing xml compiled in' } +// set to TRUE to enable correct decoding of and values +var xmlrpc_null_extension = false; +// set to TRUE to enable encoding of php NULL values to instead of +var xmlrpc_null_apache_encoding = false; + var _xh = null; // Please note that MS says you should only use versions 6 and 3... @@ -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); } @@ -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. * @@ -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) { @@ -1049,7 +1064,14 @@ xmlrpcval.prototype.serialize = function (charset_encoding) var result = ''+base64_encode(this.me)+''; break; case 9: - var result = ''; + if (xmlrpc_null_apache_encoding) + { + var result = ''; + } + else + { + var result = ''; + } break; case 2: var result = '\n\n'; @@ -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') @@ -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;