pax_global_header00006660000000000000000000000064121424262620014513gustar00rootroot0000000000000052 comment=91419a7470dc9ce75fc8b96f07f9feeed311673f lua-soap-3.0+git91419a7/000077500000000000000000000000001214242626200145155ustar00rootroot00000000000000lua-soap-3.0+git91419a7/Makefile000077500000000000000000000010471214242626200161620ustar00rootroot00000000000000# $Id: Makefile,v 1.13 2009/07/22 19:02:46 tomas Exp $ # VERSION=3.0 LUA_DIR= /usr/local/share/lua/5.1 INSTALL_DIR= $(LUA_DIR)/soap EXTRA_DIR= $(INSTALL_DIR)/client LUAS= src/soap.lua src/client.lua src/server.lua EXTRA= src/client/https.lua build clean: install: mkdir -p $(INSTALL_DIR) cp $(LUAS) $(INSTALL_DIR) mkdir -p $(EXTRA_DIR) cp $(EXTRA) $(EXTRA_DIR) uninstall: rm -rf $(INSTALL_DIR) dist: cd ..; tar czf luasoap-$(VERSION).tar.gz luasoap-$(VERSION) --exclude .git --exclude rockspecs echo Created ../luasoap-$(VERSION).tar.gz lua-soap-3.0+git91419a7/README000077500000000000000000000015201214242626200153760ustar00rootroot00000000000000LuaSOAP is a library of functions to deal with SOAP This library depends on LuaExpat. Here goes a small description of the files in the distribution README -- This file doc/us/ index.html -- Home page examples.html -- Some examples license.html -- Copyright & License luasoap.png -- LuaSOAP Logo manual.html -- Reference manual src/ soap.lua -- Source file client.lua -- Extension module over HTTP (depends on LuaSocket) server.lua -- Extension module based on CGILua src/client/ https.lua -- Extension module over HTTPS (depends on LuaSec) tests/ test.lua -- Overall API test script test-http.lua -- Client API test script test-server.lua -- Server support test script $Id: README,v 1.3 2009/07/22 19:02:46 tomas Exp $ lua-soap-3.0+git91419a7/doc/000077500000000000000000000000001214242626200152625ustar00rootroot00000000000000lua-soap-3.0+git91419a7/doc/us/000077500000000000000000000000001214242626200157115ustar00rootroot00000000000000lua-soap-3.0+git91419a7/doc/us/examples.html000077500000000000000000000126221214242626200204230ustar00rootroot00000000000000 LuaSOAP: SOAP interface to the Lua programming language
LuaSOAP
SOAP interface for the Lua programming language

Examples

SOAP elements

Follows a small example of common XML constructions written in LuaSOAP.
local simple = { tag = "symbol", "DEF", } --> <symbol>DEF</symbol>

local simple_attr = {
	tag = "symbol",
	anAttribute = "aValue",
	"DEF",
} --> <symbol anAttribute="aValue">DEF</symbol>

local structured = {
	tag = "PriceAndVolume",
	{ tag = "LastTradePrice", 34.5, },
	{ tag = "DayVolume", 10000, },
} --> <PriceAndVolume><LastTradePrice>34.5</LastTradePrice><DayVolume>10000</DayVolume></PriceAndVolume>

local structured_attr = {
	{ tag = "stooges",
		{
			tag = "curly",
			attr = { "xsi:type", ["xsi:type"] = "xsd:int", },
			-21,
		},
		{
			tag = "larry",
			attr = { "xsi:type", ["xsi:type"] = "xsd:int", },
			59,
		},
		{
			tag = "moe",
			attr = { "xsi:type", ["xsi:type"] = "xsd:int", },
			11,
		},
	},
} --> <stooges><curly xsi:type="xsd:int">-21</curly><larry xsi:type="xsd:int">59</larry><moe xsi:type="xsd:int">11</moe></stooges>

Escaping example

Below is an example of a simple way of escaping strings that contain special characters. Careful must be taken to non-ASCII characters since they have to be converted according to the locale/encoding.
local escaped_element = {
	tag = "StringEscapingTest",
	{ tag = "string", "<this was automatically escaped", },
	{ tag = "string", 'do not re-escape my &', },
} --> <StringEscapingTest><string>&lt;this was automatically escaped&gt;</string><string>do not re-escape my &amp;</string></StringEscapingTest>

Client example

Below is a small sample code displaying the use of the library in a client application. Note that the external tag might not be provided in the entries table, since the method field will be used for that purpose.
local client = require "soap.client"
local ns, meth, ent = client.call {
	url = "http://soap.4s4c.com/ssss4c/soap.asp", 
	soapaction = "doubler",
	method = "http://simon.fell.com/calc",
	entries = { -- `tag' will be filled with `method' field
		{
			tag = "nums",
			attr = {
				["xmlns:SOAP-ENC"] = "http://schemas.xmlsoap.org/soap/encoding/",
				["SOAP-ENC:arrayType"] = "xsd:int[5]",
			},
			{ tag = "number", 10 },
			{ tag = "number", 20 },
			{ tag = "number", 30 },
			{ tag = "number", 50 },
			{ tag = "number", 100 },
		},
	}
}
print("namespace = ", ns, "element name = ", meth)
for i, elem in ipairs (ent[1]) do
	print (elem[1])
end

Valid XHTML 1.0!

$Id: examples.html,v 1.2 2009/07/22 19:02:46 tomas Exp $

lua-soap-3.0+git91419a7/doc/us/index.html000077500000000000000000000133111214242626200177100ustar00rootroot00000000000000 LuaSOAP: SOAP interface to the Lua programming language
LuaSOAP
SOAP interface for the Lua programming language

Overview

LuaSOAP is a library to ease the use of SOAP. LuaSOAP provides a very simple API that convert Lua tables to and from XML documents. It uses LuaExpat to handle XML documents.

LuaSOAP is free software and uses the same license as Lua 5.1.

Status

Current version is 3.0. It was developed for Lua 5.X.

Download

LuaSOAP can be downloaded in source code from its GitHub page. LuaSOAP can also be installed via LuaRocks with the following command line:

luarocks install luasoap

History

LuaSOAP 3.0 [13/Apr/2012]
  • Addition of automatic escaping of special characters (thanks to Seth Behunin)
  • Bug correction: ignoring soap:Header while decoding soap message (thanks to Humberto Anjos)
  • Reimplementation to make it work in all Lua 5.X versions
  • Removal of soap.client.https pseudo-module (see HTTPS and SOAP over other transport layers)
LuaSOAP 2.0.2 [27/Dec/2010]
LuaSOAP 1.0 beta [2/Dec/2004]
LuaSOAP 1.0 alpha [4/Apr/2004]

Credits

LuaSOAP was designed by Roberto Ierusalimschy, André Carregal and Tomás Guisasola as part of the Kepler Project which holds its copyright. It was implemented by Tomás Guisasola and Pablo Musa with invaluable contributions from Bruno Silvestre.

LuaSOAP development was sponsored by PUC-Rio, Fábrica Digital and FINEP.

Contact us

For more information please contact us. Comments are welcome!

Valid XHTML 1.0!

$Id: index.html,v 1.14 2009/07/22 19:02:46 tomas Exp $

lua-soap-3.0+git91419a7/doc/us/license.html000077500000000000000000000114061214242626200202260ustar00rootroot00000000000000 LuaSOAP: SOAP interface to the Lua programming language
LuaSOAP
SOAP interface for the Lua programming language

License

LuaSOAP is free software: it can be used for both academic and commercial purposes at absolutely no cost. There are no royalties or GNU-like "copyleft" restrictions. LuaSOAP qualifies as Open Source software. Its licenses are compatible with GPL. LuaSOAP is not in the public domain and The Kepler Project keep its copyright. The legal details are below.

The spirit of the license is that you are free to use LuaSOAP for any purpose at no cost without having to ask us. The only requirement is that if you do use LuaSOAP, then you should give us credit by including the appropriate copyright notice somewhere in your product or its documentation.

The LuaSOAP library is designed and implemented by Roberto Ierusalimschy, André Carregal, Tomás Guisasola and Pablo Musa. The implementation is not derived from licensed software.


Copyright © 2003-2011 The Kepler Project.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Valid XHTML 1.0!

$Id: license.html,v 1.6 2009/07/22 19:02:46 tomas Exp $

lua-soap-3.0+git91419a7/doc/us/luasoap.png000077500000000000000000000173501214242626200200740ustar00rootroot00000000000000PNG  IHDRL\gIDATxy\SWHaŽ@APYD**/2uku*]tZO󾝾v8uWܠnP+ʪeM@ {)fo+9s==s\a7w7`f~ڀaxzzdX,%=<<"##1]l,f>} H"D"@pp~;]@Ӱp_%  /_b555UUUL&4 8Nuu˗/q8H`ѢE&Y,%GGG&9;dll KKKsd_h4ʕ+|>%GGqTf;::KJJ\]]}}}]jaA֭['==ԩS۶mCK׮]`0RŒd__x-?z@ R(;;;E&G&&&d+;; Jفa ABʺzjiiiZZ|@lllDDHDX{zzzffӖY \ڵ6>>kus#$&Rx#$5AԻ̹ jmmmnnf8/66f?+**(Jtt4h4Ǔd9似<%Ąժ*HRq8#AO7}YO0ҥKɇ[s<),,d0^^^\.qӦM^^^8"0re2 *++spp`0d2YiF8Y)H$耀tC:5uw{ud_8v,%={V lٲ^񊊊LΝ;=Liii[[Ltqq ollupp'&&L[ 6(vFFx~c\KJhljs8 jmmڴi [l,))Q^ ;w޼y3 r@ pttdXlYYYkdddttT93#NOoPUտm 򗿘˗+cX[[ۺ:ypmfmm-`aaN""""AP]]O?X,'''++ٗgIIavv;8XEG:-`ffF1ZYYd2|Ahh|*9?m۶q8۷o+ݳgǏW%9 v|\}ESSS0 6W k׮L Et-}&'EO^2 zEyyy]]@ t0 |vٲesVzBVZ% ;O…gjGLC!<|(*((޾VNLLdɒyVƧd9(+HTPP`ee?@ x<>/o &##… ׮][L7}||Pz0UR Çb877W$aX`oݺw߅v7*SJjhHMR {ѢE5= 2%%euuu===RTYhaefT(`a:8XQ(VD*F0^" 9bc0 8<<|޽~ww$:^\\LP bjJT[;@ >z4<61!@x#degga@z4aeF'a O:B(͛@dǎkiiqww7 7گ_A { 9am@m4<둕Օ<ooU4+)j ?^WWb####""f/ϝ;G&׭[yG*54\o׮${zSR.$=<P`0N?;;{MZh}JM66p#GRdp|=p/!BybbggŢӽ 22:;;_T\\lmmQЛo@~<@ 2/T ɠ"ÔB}5]5TTTEFFPWW`ggW^^.Z[[dB{y54<ĸP(0##~oL^^7߬b*a ,l6A###===O>"Ͳbٮ]?{G,!p^H˶o%_`+–l'x<?FkdCuQ(d"##T~egݽRGb͛DÇ?W[;F \>o{]U+a@twwwssAp`` $$>ח9AZڥ!sW/uF0 d7?%Bi6׋oi-,lr[se*++;;;y<۷t_ZZzmP(MMX]?7쳤@}T ]b{-x{ '11AG7'oyʕ(=H$s6dd!<=-޷&ࢢéٳD$P;;pWWGxDQUU_ 89$sMWWW$giiAL&xxxh@yyOnn \evMKPM ㉕ DFhfK`XmmmQQQ:6A۷=J$_!</..NScc;v2ҠM}5gnA_6;;jMt- {G^|ź={n3ӦU{naX,ر45-AJ䰰0sW1 kkkWW׮8]kt7eeo^mA믔t*dmۦ[A-H0.HYǣht:=000>>^i1' ~xl:NoobO>-wlpU)Ѻs 0."@Xt;4v:ڵ~>))8ڞɜ5UQ.% Å4MSLU>X$XYaCB(ǎ=4Ij011_b2L&S~^W-ff <2 ^^9MJ(<<<<<\ tttVVVBIQUǝԛ[oEH$mmxFsxxezzD?~lmmUސ\xŋgff^xaaarդh8gZW_S$pss;p&Pkk%Kh$IN.Çt9w?%P(,ꆐ-[V۵Ǚݿ?hL.&@YY2 =n"!޻uC0 d2$+skWIo_Gh w[rtA4S'Jkܩ6[vE}0 8Q]0cbъ6M6vu;M!%ٟTgmHb= E%`*o)--cHw숐L0QTbw]' m&a裲&ҵ-[==Q 7:8XmCGHѣOj 9:ZP  1^Q{rK}a~|a5fQ:PSS=Z?X/^loc;H=ds6dd0ޯaLMDJнmdRC~ a |mJ0 sQSH_nu7`ȟ}5ENh,سg)~v +VxX?.ߵ ~|Mi\21iڇ 3<>_9H/oA X 'bs/{}89}p+Ow8OW"~|+qQݙ!잞v:,22!̼wO+XyyŪlrO<- b&χQe9S]]f%J%ꌃ垂БDRDpc .Wӧ *Ƚm!9  jv5ۼ^3utA|>_fww[UAYrzn0<33cPQ(06 g\\T'11:M'''9{nU t@R yyQNN,# U#9:9:: #&[YsbsEŴɜhog>y2<>om}ϴNӝ~d OHL/^̒> Ï ?^K$=a{%qeppPa^=D"innV8BN"\쬾oY5)<7r/o0 H$Mެ.))Arr׌5(+VOt[DP|lA $oTv,-;;5'_lR^hq|M灤INPPPggT 7_J5K1q>$~Vkh}*yeF4jjG ֭ 'www/"iݽ+zNO g۵6cY" G]"AYɸtK~~XX//l'v[[i٦.V{׾gE|뭛iqq߽{ɰX, rxU|8yq(Y!!议}rͥL]r :}G9dd[F\^./}uPǏٳTglmmcccr$YXX~gF`/vfOh8tAo`ZNu57XQD}TWG^xOFP(ꫯRSS&bD,df^U$J*`~PS믟?}zP95%Ӫ#G99sQ}UV֓vĉuT~M4P7u_~ZבlC }_}Nw0vB+Wz%&z{{q84oh`w tVEP Vii{bl+v~!ϧRiiiZ'qH3fODxin Ƽ`ݳO.[PPe~3-y|i"H$:'+Vvt :{wo{!d(JXXXUUFFΟts{! '',x%%%q8/m~Cn=74UoH]viqWD\Ǚ3_/i֭\$P(?Ԅ$2`a^:͛þr5 ?}p+**@·Q-~?4?yO>Y_TM^U1JRT$Bt6?9СUV_gIk2ڇ 觟~ DF\Ჲӧ} uH;,ѫ&? Q- ::`nn?o;o&H(.KUUYr;wFF8a(8649NO0>)$;'$$ܹsGLJD}򅰇>\̌#H35^* E"!wi%(K"?Fء[?9$BD"?_k&'s֕@}I¾}:dEEECCC;wۤW Ś Z~zie[?.dnܸݽ}vWW3 `ppP+$Ua2g?ɜ1v88Xٳw+Ņ ^^H?ϡ N_t3''{DҒγg**L7,Dݱ#"33x& 0}`0 dM+1>ο}wdeR55/==P 0'c;|rPPPJJIJ񺺡Vfo/gxxJrERP^sq r@xNs6GD\ |>é56 S4ĐVDvw†yM''۷#?62 Zd*vZӾU󡎆a4j0>}aÆ4hŋCCC+V~iaxzzZgz f +**lmm322<< LuaSOAP: SOAP interface to the Lua programming language
LuaSOAP
SOAP interface for the Lua programming language

Introduction

LuaSOAP is a Lua library to ease the use of SOAP. It enables a Lua program to:

  • Encode and decode SOAP messages without having to deal directly with XML code
  • Invoke remote Web Services without having to deal directly with SOAP messages

LuaSOAP provides a very simple API and an abstraction layer over XML avoiding manipulation of string representation of data structures.

LuaSOAP is based on LuaExpat and on Lua 5.1. The abstraction layer over HTTP depends on LuaSocket 2.0. An optional layer over HTTPS depends on LuaSec 0.4.

Installation

LuaSOAP is a Lua library composed by a main module (soap.lua) and some extensions: client.lua and server.lua. The main module must be copied to your package.path and the other two files to a soap directory in your package.path.

LuaSOAP can also be installed via LuaRocks with the command luarocks install luasoap. You can check the available rocks at LuaRocks' main repository.

LuaSOAP elements

LuaSOAP elements are always represented by Lua tables except strings. A LuaSOAP element is a table of the form defined by the Lua Object Model from the LuaExpat library. The table has the following characteristics:

  • a special field called tag with the element's name;
  • a special optional field called attr with the element's attributes (see next section);
  • the element's children are stored at the array-part of the table. A child could be an ordinary string or a LuaSOAP element (a Lua table following these same rules).

Attributes

The special field attr is a Lua table that stores the LuaSOAP element's attributes as pairs <key>=<value>. To assure an order (if necessary), the sequence of keys should be placed at the array-part of that table.

This documentation provides a detailed example which shows some common use cases.

Escaping and special characters

Since LuaSOAP 3.0, the library took the responsibility to escape data inside LuaSOAP elements (entries field of soap envelope; see function soap.encode below). Therefore, XML special characters such as < and > are automatically converted to the corresponding XML entities (&lt; and &gt;, respectively).

This documentation provides examples which show some common use cases.

Basic support

The module soap implements all basic support for encoding and decoding SOAP messages. There are two functions:

  • encode(args) => envelope
    Builds a SOAP document containing a SOAP-Envelope element. It receives a table with the following fields:
    • namespace a string with an URI indicating the namespace (xmlns) atribute of the request,
    • method a string with the method's name,
    • entries an array (a table with numeric keys) of LuaSOAP elements,
    • header (optional) a table of headers (soap:Header element; a LuaSOAP element too),
    • soapversion (optional; default = 1.1) a number with the SOAP version (currently supported versions are 1.1 and 1.2),
    • internal_namespace (optional; default = "") a string with the `internal' namespace (xmlns:internal_namespace)
    The result is always a string containing the SOAP document.
    The function can raise errors in case the args table is mal formed.
  • decode (method_response) => namespace, method_name, elements
    Disassembles a SOAP document into Lua objects. It receives a string containing the SOAP document. The results are: the namespace (string), the SOAP-element method's name (string) and a table with the contents of the SOAP Body. Each element of the elements table can be a string or a LuaSOAP element.

Client side

The module soap.client implements a stand-alone client which works over HTTP and is based on LuaSocket 2.0. The following function is provided:

  • call (args) => namespace, method_name, elements
    It encapsulates the call of encode and decode over a connection to an HTTP server, thus the arguments are passed to the encode function and the results received from the decode function. It receives a table with the following fields:
    • url a string with the URL of the service (the protocol should be http or https, which requires the load of LuaSec's ssl.https module),
    • soapaction a string with the value of the SOAPAction header,
    • encoding (optional; default = "") a string with the text encoding (usually "utf-8" or "iso-8859-1"),
    • other arguments to the encode function
    The results are the same as the decode function: the namespace (string), the SOAP-element method's name (string) and a table with the contents of the SOAP Body.

HTTPS and SOAP over other transport layers

LuaSOAP client module was designed to work over HTTP (via LuaSocket's socket.http module) and HTTPS (via LuaSec's ssl.https module). In fact, it could be used over other protocols since they provide LuaSocket's socket.http.request function.

The soap.client.call function inspects the URL to check what protocol the SOAP message is supposed to be transfered upon. Then, it looks for a function called request at the soap.client.protocol (where protocol is a table which has an entry called request which is a function with the same signature of LuaSocket's socket.http.request. Thus, the support fot HTTPS can be enabled by a program with the following lines:

local soap_client = require"soap.client"
soap_client.https = require"ssl.https"

By following this approach, one could extend LuaSOAP to use another protocol by implementing a function equivalent to LuaSocket's socket.http.request or LuaSec's ssl.https.request.

References

Here is a list of related documentation:

Valid XHTML 1.0!

$Id: manual.html,v 1.10 2009/08/10 19:04:40 tomas Exp $

lua-soap-3.0+git91419a7/rockspecs/000077500000000000000000000000001214242626200165115ustar00rootroot00000000000000lua-soap-3.0+git91419a7/rockspecs/luasoap-2.0.0-0.rockspec000077500000000000000000000011241214242626200225010ustar00rootroot00000000000000package = "luasoap" version = "2.0.0-0" source = { url="http://luasoap.luaforge.net/luasoap-1.1-1.tar.gz", } description = { summary = "Support for SOAP", detailed = "LuaSOAP provides a very simple API that convert Lua tables to and from XML documents", homepage = "http://luasoap.luaforge.net/", license = "MIT/X11", } dependencies = { "lua >= 5.1", "luaexpat >= 1.1.0-3", "luasocket >= 2.0.2-1", } build = { type = "builtin", modules = { soap = "src/soap.lua", ["soap.server"] = "src/server.lua", ["soap.client"] = "src/client.lua", } } lua-soap-3.0+git91419a7/rockspecs/luasoap-2.0.1-0.rockspec000077500000000000000000000012401214242626200225010ustar00rootroot00000000000000package = "luasoap" version = "2.0.1-0" source = { url = "", url="http://github.com/downloads/tomasguisasola/luasoap/luasoap-2.0.1.tar.gz", md5="ebac9d3a04a845765d498907a71429c2", } description = { summary = "Support for SOAP", detailed = "LuaSOAP provides a very simple API that convert Lua tables to and from XML documents", homepage = "http://luasoap.luaforge.net/", license = "MIT/X11", } dependencies = { "lua >= 5.1", "luaexpat >= 1.1.0-3", "luasocket >= 2.0.2-1", } build = { type = "builtin", modules = { soap = "src/soap.lua", ["soap.server"] = "src/server.lua", ["soap.client"] = "src/client.lua", } } lua-soap-3.0+git91419a7/rockspecs/luasoap-2.0.2-1.rockspec000077500000000000000000000012401214242626200225030ustar00rootroot00000000000000package = "luasoap" version = "2.0.2-1" source = { url = "", url="http://github.com/downloads/tomasguisasola/luasoap/luasoap-2.0.2.tar.gz", md5="3aafa06f3a65e65f4ee08e12b89ec583", } description = { summary = "Support for SOAP", detailed = "LuaSOAP provides a very simple API that convert Lua tables to and from XML documents", homepage = "http://luasoap.luaforge.net/", license = "MIT/X11", } dependencies = { "lua >= 5.1", "luaexpat >= 1.1.0-3", "luasocket >= 2.0.2-1", } build = { type = "builtin", modules = { soap = "src/soap.lua", ["soap.server"] = "src/server.lua", ["soap.client"] = "src/client.lua", } } lua-soap-3.0+git91419a7/rockspecs/luasoap-3.0-1.rockspec000077500000000000000000000011401214242626200223430ustar00rootroot00000000000000package = "luasoap" version = "3.0-1" source = { url = "", url="http://github.com/downloads/tomasguisasola/luasoap/luasoap-3.0.tar.gz", md5="", } description = { summary = "Support for SOAP", detailed = "LuaSOAP provides a very simple API that convert Lua tables to and from XML documents", homepage = "", license = "MIT/X11", } dependencies = { "lua >= 5.0", "luaexpat >= 1.1.0-3", "luasocket >= 2.0.2-1", } build = { type = "builtin", modules = { soap = "src/soap.lua", ["soap.server"] = "src/server.lua", ["soap.client"] = "src/client.lua", } } lua-soap-3.0+git91419a7/rockspecs/luasoap-https-1.1-1.rockspec000077500000000000000000000011571214242626200235120ustar00rootroot00000000000000package = "luasoap-https" version = "1.1-1" source = { url="http://luasoap.luaforge.net/frs/download.php/??/luasoap-https-1.1-1.tar.gz", } description = { summary = "Support for SOAP over HTTPS", detailed = [[LuaSOAP provides a very simple API that convert Lua tables to and from XML documents. This module provides a way to use SOAP over HTTPS.]], homepage = "http://luasoap.luaforge.net/", license = "MIT/X11", } dependencies = { "lua >= 5.1", "luasoap >= 1.1-1", "luasec >= 0.4-1", } build = { type = "builtin", modules = { ["soap.client.https"] = "src/client/https.lua", } } lua-soap-3.0+git91419a7/rockspecs/luasoap-https-1.1-2.rockspec000077500000000000000000000011501214242626200235040ustar00rootroot00000000000000package = "luasoap-https" version = "1.1-2" source = { url="http://www.tecgraf.puc-rio.br/~tomas/luasoap/luasoap-2.0.0-1.tar.gz", } description = { summary = "Support for SOAP over HTTPS", detailed = [[LuaSOAP provides a very simple API that convert Lua tables to and from XML documents. This module provides a way to use SOAP over HTTPS.]], homepage = "http://luasoap.luaforge.net/", license = "MIT/X11", } dependencies = { "lua >= 5.1", "luasoap >= 1.1-1", "luasec >= 0.4-1", } build = { type = "builtin", modules = { ["soap.client.https"] = "src/client/https.lua", } } lua-soap-3.0+git91419a7/src/000077500000000000000000000000001214242626200153045ustar00rootroot00000000000000lua-soap-3.0+git91419a7/src/client.lua000077500000000000000000000077411214242626200173010ustar00rootroot00000000000000--------------------------------------------------------------------- -- SOAP client. -- Default is over HTTP, but one can install other modules such as -- client.https to provide access via HTTPS. -- See Copyright notice in license.html -- $Id: client.lua,v 1.3 2009/07/22 19:02:46 tomas Exp $ --------------------------------------------------------------------- local assert, tonumber, tostring, pcall = assert, tonumber, tostring, pcall local concat = require("table").concat local ltn12 = require("ltn12") local soap = require("soap") local _M = { _COPYRIGHT = "Copyright (C) 2004-2011 Kepler Project", _DESCRIPTION = "LuaSOAP provides a very simple API that convert Lua tables to and from XML documents", _VERSION = "LuaSOAP 3.0 client", -- Support for SOAP over HTTP is default and only depends on LuaSocket http = require("socket.http"), } local xml_header_template = '' local mandatory_soapaction = "Field `soapaction' is mandatory for SOAP 1.1 (or you can force SOAP version with `soapversion' field)" local mandatory_url = "Field `url' is mandatory" local invalid_args = "Supported SOAP versions: 1.1 and 1.2. The presence of soapaction field is mandatory for SOAP version 1.1.\nsoapversion, soapaction = " local suggested_layers = { http = "socket.http", https = "ssl.https", } --------------------------------------------------------------------- -- Call a remote method. -- @param args Table with the arguments which could be: -- url: String with the location of the server. -- soapaction: String with the value of the SOAPAction header. -- namespace: String with the namespace of the elements. -- method: String with the method's name. -- entries: Table of SOAP elements (LuaExpat's format). -- header: Table describing the header of the SOAP-ENV (optional). -- internal_namespace: String with the optional namespace used -- as a prefix for the method name (default = ""). -- soapversion: Number with SOAP version (default = 1.1). -- @return String with namespace, String with method's name and -- Table with SOAP elements (LuaExpat's format). --------------------------------------------------------------------- function _M.call(args) local soap_action, content_type_header if (not args.soapversion) or tonumber(args.soapversion) == 1.1 then soap_action = '"'..assert(args.soapaction, mandatory_soapaction)..'"' content_type_header = "text/xml" elseif tonumber(args.soapversion) == 1.2 then soap_action = nil content_type_header = "application/soap+xml" else assert(false, invalid_args..tostring(args.soapversion)..", "..tostring(args.soapaction)) end local xml_header = xml_header_template if args.encoding then xml_header = xml_header:gsub('"%?>', '" encoding="'..args.encoding..'"?>') end local request_body = xml_header..soap.encode(args) local request_sink, tbody = ltn12.sink.table() local headers = { ["Content-Type"] = content_type_header, ["content-length"] = tostring(request_body:len()), ["SOAPAction"] = soap_action, } if args.headers then for h, v in pairs (args.headers) do headers[h] = v end end local url = { url = assert(args.url, mandatory_url), method = "POST", source = ltn12.source.string(request_body), sink = request_sink, headers = headers, } local protocol = url.url:match"^(%a+)" -- protocol's name local mod = assert(_M[protocol], '"'..protocol..'" protocol support unavailable. Try soap.client.'..protocol..' = require"'..suggested_layers[protocol]..'" to enable it.') local request = assert(mod.request, 'Could not find request function on module soap.client.'..protocol) local err, code, headers, status = request(url) local body = concat(tbody) assert(tonumber(code) == 200, "Error on request: "..tostring(err or code).."\n\n"..tostring(body)) local ok, error_or_ns, method, result = pcall(soap.decode, body) assert(ok, "Error while decoding: "..tostring(error_or_ns).."\n\n"..tostring(body)) return error_or_ns, method, result end --------------------------------------------------------------------- return _M lua-soap-3.0+git91419a7/src/client/000077500000000000000000000000001214242626200165625ustar00rootroot00000000000000lua-soap-3.0+git91419a7/src/client/https.lua000077500000000000000000000005221214242626200204310ustar00rootroot00000000000000--------------------------------------------------------------------- -- SOAP client over HTTPS. -- -- See Copyright notice in license.html -- $Id: https.lua,v 1.2 2009/05/27 13:22:41 tomas Exp $ --------------------------------------------------------------------- local client = require"soap.client" client.https = require"ssl.https" lua-soap-3.0+git91419a7/src/server.lua000077500000000000000000000304311214242626200173210ustar00rootroot00000000000000--------------------------------------------------------------------- -- LuaSOAP support for service development. -- See Copyright Notice in license.html -- $Id:$ --------------------------------------------------------------------- local next, type, tostring, pcall, unpack, pairs, ipairs = next, type, tostring, pcall, unpack, pairs, ipairs local error, assert = error, assert local table = require"table" local string = require"string" local cgilua = cgilua local soap = require"soap" local encoding = "iso-8859-1" local xml_header = '\n' local __methods __methods = { listMethods = function (namespace) local l = {} for name in pairs(__methods) do table.insert(l, { tag = "methodName", name }) end return soap.encode({method = "listMethodsResponse", entries = l}) end, } local __service = { -- name -- namespace -- url -- soap_action -- wsdl (opt) -- disco (opt) } --------------------------------------------------------------------- local function respond(resp, header) cgilua.header("Content-length", string.len(resp)) cgilua.header("Connection", "close") cgilua.contentheader("text", "xml") if header then cgilua.put(header) end cgilua.put(resp) end --------------------------------------------------------------------- local function builderrorenvelope(faultcode, faultstring, extra) faultstring = faultstring:gsub("([<>])", { ["<"] = "<", [">"] = ">", }) return soap.encode({ entries = { { tag = "faultcode", faultcode, }, { tag = "faultstring", faultstring, }, extra, }, method = "soap:Fault", }) end --------------------------------------------------------------------- local function decodedata(doc) local namespace, elem_name, elems = soap.decode(doc) local func = __methods[elem_name].method assert(type(func) == "function", "Unavailable method: `"..tostring(elem_name).."'") return namespace, func, (elems or {}) end --------------------------------------------------------------------- local function callfunc(func, namespace, arg_table) local result = { pcall(func, namespace, arg_table) } local ok = result[1] if not ok then result = builderrorenvelope("soap:ServiceError", result[2]) else table.remove(result, 1) if #result == 1 then result = result[1] end end return ok, result end --------------------------------------------------------------------- local function wsdl_gen_type_aux(message) if not next(message, nil) then return "" end local buffer = { string.format([[ ]], message.name) } for _, field in ipairs(message) do local min, max if type(field.occurrence) == "table" then min, max = field.occurrence[1], field.occurrence[2] elseif type(field.occurrence) == "string" then min, max = field.occurrence, field.occurrence else min, max = 1, 1 end local _type = field.type or "string" table.insert(buffer, string.format([[ ]], min, max, field.name, _type)) end table.insert(buffer, [[ ]]) return table.concat(buffer) end local function wsdl_gen_type(desc) return wsdl_gen_type_aux(desc.message) .. wsdl_gen_type_aux(desc.response) end --------------------------------------------------------------------- local function wsdl_gen_message(desc) local in_params, out_params = "", "" if desc.message.name then in_params = '\n \n ' end if desc.response.name then out_params = '\n \n ' end return string.format([[ %s %s]], desc.name, in_params, desc.name, out_params) end --------------------------------------------------------------------- local function wsdl_gen_port_type(desc) return string.format([[ ]], desc.name, desc.name, desc.name) end --------------------------------------------------------------------- local function wsdl_gen_binding(desc) local soap_action = '' if __service.soap_action then soap_action = 'soapAction="'..__service.soap_action..desc.name..'"' end return string.format([[ ]], desc.name, soap_action) end --------------------------------------------------------------------- local function wsdl_gen_http_binding(desc) return string.format([[ ]], desc.name, desc.name) end --------------------------------------------------------------------- local function generate_wsdl() local buffer = { xml_header, string.format([[ ]], __service.namespace, __service.namespace) } -- types --------------------------------------------- table.insert(buffer, string.format([[ ]], __service.namespace)) for _, method in pairs(__methods) do if type(method) == "table" then table.insert(buffer, method.wsdl_type) end end table.insert(buffer, [[ ]]) -- message --------------------------------------------- for _, method in pairs(__methods) do if type(method) == "table" then table.insert(buffer, method.wsdl_message) end end -- portType --------------------------------------------- table.insert(buffer, string.format([[ ]], __service.name)) for _, method in pairs(__methods) do if type(method) == "table" then table.insert(buffer, method.wsdl_port_type) end end table.insert(buffer, "\n ") table.insert(buffer, string.format([[ ]], __service.name)) for _, method in pairs(__methods) do if type(method) == "table" then table.insert(buffer, (method.wsdl_port_type:gsub("Soap", "HttpPost"))) end end table.insert(buffer, "\n ") -- binding --------------------------------------------- -- Soap table.insert(buffer, string.format([[ ]], __service.name, __service.name)) for _, method in pairs(__methods) do if type(method) == "table" then table.insert(buffer, method.wsdl_binding) end end table.insert(buffer, " ") -- Soap12 table.insert(buffer, string.format([[ ]], __service.name, __service.name)) for _, method in pairs(__methods) do if type(method) == "table" then table.insert(buffer, (method.wsdl_binding:gsub("") -- HttpPost table.insert(buffer, string.format([[ ]], __service.name, __service.name)) for _, method in pairs(__methods) do if type(method) == "table" then table.insert(buffer, method.wsdl_http_binding) end end table.insert(buffer, " ") -- service --------------------------------------------- table.insert(buffer, string.format([[ ]], __service.name, __service.name, __service.name, __service.url, __service.name, __service.name, __service.url, __service.name, __service.name, __service.url)) table.insert(buffer, [[ ]]) return table.concat(buffer) end --------------------------------------------------------------------- local function generate_disco() return xml_header.."" end --------------------------------------------------------------------- -- Registers information needed to respond to WSDL and discovery -- requests -- @param name String with the name of the service -- @param namespace String with the namespace of the service -- @param url String with the url of the service -- @param wsdl String with a WSDL response message (optional) -- @param disco String with a discovery response message (optional) --------------------------------------------------------------------- local function register_service_info(name, namespace, url, wsdl, disco) __service.name = name __service.namespace = namespace __service.url = url __service.wsdl = wsdl __service.disco = disco __service.soap_action = string.gsub(url, "[^/]*$", "") end --------------------------------------------------------------------- -- Exports methods that can be used by the server. -- @param desc Table with the method description. --------------------------------------------------------------------- local function export(desc) desc.response.name = desc.response.name or desc.message.name.."Response" __methods[desc.name] = { message = desc.message.name, response = desc.response.name, wsdl_type = wsdl_gen_type(desc), wsdl_message = wsdl_gen_message(desc), wsdl_port_type = wsdl_gen_port_type(desc), wsdl_binding = wsdl_gen_binding(desc), wsdl_http_binding = wsdl_gen_http_binding(desc), method = function (...) -- ( namespace, unpack(arguments) ) local res = desc.method(...) return soap.encode({namespace = __service.namespace, method = desc.response.name, entries = res}) end, } end --------------------------------------------------------------------- local function fatalerrorfunction(msg) respond(builderrorenvelope("soap:ServerError", msg)) end --------------------------------------------------------------------- -- Handles the request received by the calling script. -- @param postdata String with POST data from the server. -- @param querystring String with the query string. --------------------------------------------------------------------- local function handle_request(postdata, querystring) cgilua.seterroroutput(fatalerrorfunction) local namespace, func, arg_table local header if postdata then namespace, func, arg_table = decodedata(postdata) header = xml_header else if querystring and querystring:lower() == "wsdl" then -- WSDL service func = function () return __service.wsdl or generate_wsdl() end elseif querystring == "disco" then -- discovery service func = function () return __service.disco or generate_disco() end else func = __methods["listMethods"] header = xml_header end arg_table = {} end local ok, result = callfunc(func, namespace, arg_table) respond(result, header) end --------------------------------------------------------------------- return { _COPYRIGHT = "Copyright (C) 2004-2011 Kepler Project", _DESCRIPTION = "LuaSOAP provides a very simple API that convert Lua tables to and from XML documents", _VERSION = "LuaSOAP 3.0 service helping functions", builderrorenvelope = builderrorenvelope, export = export, generate_disco = generate_disco, generate_wsdl = generate_wsdl, handle_request = handle_request, register_service_info = register_service_info, } lua-soap-3.0+git91419a7/src/soap.lua000077500000000000000000000177461214242626200167730ustar00rootroot00000000000000--------------------------------------------------------------------- -- LuaSoap implementation for Lua. -- See Copyright Notice in license.html -- $Id: soap.lua,v 1.9 2009/07/22 19:02:46 tomas Exp $ --------------------------------------------------------------------- local assert, error, pairs, tonumber, tostring, type = assert, error, pairs, tonumber, tostring, type local table = require"table" local tconcat, tinsert, tremove = table.concat, table.insert, table.remove local string = require"string" local gsub, strfind, strformat = string.gsub, string.find, string.format local max = require"math".max local lom = require"lxp.lom" local parse = lom.parse local tescape = { ['&'] = '&', ['<'] = '<', ['>'] = '>', ['"'] = '"', ["'"] = ''', } --------------------------------------------------------------------- -- Escape special characters. --------------------------------------------------------------------- local function escape (text) return (gsub (text, "([&<>'\"])", tescape)) end local tunescape = { ['&'] = '&', ['<'] = '<', ['>'] = '>', ['"'] = '"', ['''] = "'", } --------------------------------------------------------------------- -- Unescape special characters. --------------------------------------------------------------------- local function unescape (text) return (gsub (text, "(&%a+%;)", tunescape)) end local serialize --------------------------------------------------------------------- -- Serialize the table of attributes. -- @param a Table with the attributes of an element. -- @return String representation of the object. --------------------------------------------------------------------- local function attrs (a) if not a then return "" -- no attributes else local c = {} if a[1] then for i = 1, #a do local v = a[i] c[i] = strformat ("%s=%q", v, a[v]) end else for i, v in pairs (a) do c[#c+1] = strformat ("%s=%q", i, v) end end if #c > 0 then return " "..tconcat (c, " ") else return "" end end end --------------------------------------------------------------------- -- Serialize the children of an object. -- @param obj Table with the object to be serialized. -- @return String representation of the children. --------------------------------------------------------------------- local function contents (obj) if not obj[1] then return "" else local c = {} for i = 1, #obj do c[i] = serialize (obj[i]) end return tconcat (c) end end --------------------------------------------------------------------- -- Serialize an object. -- @param obj Table with the object to be serialized. -- @return String with representation of the object. --------------------------------------------------------------------- serialize = function (obj) local tt = type(obj) if tt == "string" then return escape(unescape(obj)) elseif tt == "number" then return obj elseif tt == "table" then local t = obj.tag assert (t, "Invalid table format (no `tag' field)") return strformat ("<%s%s>%s", t, attrs(obj.attr), contents(obj), t) else return "" end end --------------------------------------------------------------------- -- @param attr Table of object's attributes. -- @return String with the value of the namespace ("xmlns") field. --------------------------------------------------------------------- local function find_xmlns (attr) for a, v in pairs (attr) do if strfind (a, "xmlns", 1, 1) then return v end end end --------------------------------------------------------------------- -- Add header element (if it exists) to object. -- Cleans old header element anyway. --------------------------------------------------------------------- local header_template = { tag = "soap:Header", } local function insert_header (obj, header) -- removes old header if obj[2] then tremove (obj, 1) end if header then header_template[1] = header tinsert (obj, 1, header_template) end end local envelope_template = { tag = "soap:Envelope", attr = { "xmlns:soap", "soap:encodingStyle", "xmlns:xsi", "xmlns:xsd", ["xmlns:soap"] = nil, -- to be filled ["soap:encodingStyle"] = "http://schemas.xmlsoap.org/soap/encoding/", ["xmlns:xsi"] = "http://www.w3.org/2001/XMLSchema-instance", ["xmlns:xsd"] = "http://www.w3.org/2001/XMLSchema", }, { tag = "soap:Body", [1] = { tag = nil, -- must be filled attr = {}, -- must be filled }, } } local xmlns_soap = "http://schemas.xmlsoap.org/soap/envelope/" local xmlns_soap12 = "http://www.w3.org/2003/05/soap-envelope" --------------------------------------------------------------------- -- Converts a LuaExpat table into a SOAP message. -- @param args Table with the arguments, which could be: -- namespace: String with the namespace of the elements. -- method: String with the method's name; -- entries: Table of SOAP elements (LuaExpat's format); -- header: Table describing the header of the SOAP envelope (optional); -- internal_namespace: String with the optional namespace used -- as a prefix for the method name (default = ""); -- soapversion: Number of SOAP version (default = 1.1); -- @return String with SOAP envelope element. --------------------------------------------------------------------- local function encode (args) if tonumber(args.soapversion) == 1.2 then envelope_template.attr["xmlns:soap"] = xmlns_soap12 else envelope_template.attr["xmlns:soap"] = xmlns_soap end local xmlns = "xmlns" if args.internal_namespace then xmlns = xmlns..":"..args.internal_namespace args.method = args.internal_namespace..":"..args.method end -- Cleans old header and insert a new one (if it exists). insert_header (envelope_template, args.header) -- Sets new body contents (and erase old content). local body = (envelope_template[2] and envelope_template[2][1]) or envelope_template[1][1] for i = 1, max (#body, #args.entries) do body[i] = args.entries[i] end -- Sets method (actually, the table's tag) and namespace. body.tag = args.method body.attr[xmlns] = args.namespace return serialize (envelope_template) end -- Iterates over the children of an object. -- It will ignore any text, so if you want all of the elements, use ipairs(obj). -- @param obj Table (LOM format) representing the XML object. -- @param tag String with the matching tag of the children -- or nil to match only structured children (single strings are skipped). -- @return Function to iterate over the children of the object -- which returns each matching child. local function list_children (obj, tag) local i = 0 return function () i = i+1 local v = obj[i] while v do if type(v) == "table" and (not tag or v.tag == tag) then return v end i = i+1 v = obj[i] end return nil end end --------------------------------------------------------------------- -- Converts a SOAP message into Lua objects. -- @param doc String with SOAP document. -- @return String with namespace, String with method's name and -- Table with SOAP elements (LuaExpat's format). --------------------------------------------------------------------- local function decode (doc) local obj = assert (parse (doc)) local ns = obj.tag:match ("^(.-):") assert (obj.tag == ns..":Envelope", "Not a SOAP Envelope: ".. tostring(obj.tag)) local lc = list_children (obj) local o = lc () -- Skip SOAP:Header while o and (o.tag == ns..":Header" or o.tag == "SOAP-ENV:Header") do o = lc () end if o and (o.tag == ns..":Body" or o.tag == "SOAP-ENV:Body") then obj = list_children (o)() else error ("Couldn't find SOAP Body!") end local namespace = find_xmlns (obj.attr) local method = obj.tag:match ("%:([^:]*)$") or obj.tag local entries = {} for i = 1, #obj do entries[i] = obj[i] end return namespace, method, entries end --------------------------------------------------------------------- return { _COPYRIGHT = "Copyright (C) 2004-2013 Kepler Project", _DESCRIPTION = "LuaSOAP provides a very simple API that convert Lua tables to and from XML documents", _VERSION = "LuaSOAP 3.0", decode = decode, encode = encode, escape = escape, unescape = unescape, serialize = serialize, } lua-soap-3.0+git91419a7/tests/000077500000000000000000000000001214242626200156575ustar00rootroot00000000000000lua-soap-3.0+git91419a7/tests/test-http.lua000077500000000000000000000012601214242626200203200ustar00rootroot00000000000000-- $Id: test-http.lua,v 1.4 2009/07/22 19:02:46 tomas Exp $ local soap_client = require"soap.client" local request = { url = "http://validator.soapware.org", soapaction = "/validator1", namespace = nil, method = "easyStructTest", entries = { { tag = "stooges", { tag = "curly", attr = { "xsi:type", ["xsi:type"] = "xsd:int", }, -5 }, { tag = "larry", attr = { "xsi:type", ["xsi:type"] = "xsd:int", }, 5 }, { tag = "moe", attr = { "xsi:type", ["xsi:type"] = "xsd:int", }, 41 }, }, } } local ns, meth, ent = soap_client.call (request) assert(tonumber(ent[2][1]) == 41) request.entries[1][2][1] = "abc" soap_client.call (request) print"Ok!" lua-soap-3.0+git91419a7/tests/test-server.lua000077500000000000000000000063561214242626200206620ustar00rootroot00000000000000--------------------------------------------------------------------- -- $Id:$ --------------------------------------------------------------------- --------------------------------------------------------------------- -- Fake cgilua support local function donothing() end cgilua = { contentheader = donothing, header = donothing, put = print, seterroroutput = donothing, --function(f) f("error message") end, } local server = require("soap.server") --------------------------------------------------------------------- local fake_data = { { { codigo = 1, sequencial = 2, legenda = 'Bla', ordem = 1, }, { codigo = 1, sequencial = 1, legenda = 'bla', ordem = 2, }, { codigo = 2, sequencial = 1, legenda = 'bLA', ordem = 3, }, }, { { codigo = 3, sequencial = 2, legenda = 'BlaBla', ordem = 1, }, { codigo = 3, sequencial = 1, legenda = 'blaBla', ordem = 2, }, { codigo = 2, sequencial = 1, legenda = 'bLABla', ordem = 3, }, }, } --------------------------------------------------------------------- function lista_imagens_galeria (galeria) assert (galeria, "Nil argument #1 to 'lista_imagens_galeria'") local tg = type(galeria) assert (tg == "table", "Bad argument #1 to 'lista_imagens_galeria' (table expected, got "..tg..")") local tgid = type(galeria.id) assert (tgid == "string", "Bad argument #1 to 'lista_imagens_galeria' (number expected, got "..tgid..")") assert (tonumber(galeria) and galeria ~= "inf" and galeria ~= "nan", "Bad argument #1 to 'lista_imagens_galeria' (number expected, got {"..tostring(galeria).."}") local imgs = fake_data[galeria.id] local dados = { tag = "ImagensGaleria" } for i = 1, #imgs do local row = imgs[i] tinsert (dados, { tag = "Imagem", { tag = "codigo", row.codigo }, { tag = "sequencial", row.sequencial }, { tag = "legenda", row.legenda }, { tag = "ordem", row.ordem }, }) end return dados end --------------------------------------------------------------------- local namespace = server_name and string.format("http://%s/path/", server_name) or "http://my.server.name/path/" local script = namespace.."this_script.lua" local disco = string.format([=[ ]=], script, script, script) server.register_service_info("listaImagensGaleria", namespace, script, nil, disco) server.export { name = "listaImagensGaleria", method = lista_imagens_galeria, message = { name = "Galeria", { name = "id", occurence = 1, type = "integer", }, }, response = { name = "ImagensGaleria", { name = "Imagem", { name = "codigo", occurence = 1, type = "integer", }, { name = "sequencial", occurence = 1, type = "integer", }, { name = "legenda", occurence = 1, type = "string", }, { name = "ordem", occurence = 1, type = "integer", }, }, }, } --------------------------------------------------------------------- server.handle_request (nil, "wsdl") lua-soap-3.0+git91419a7/tests/test.lua000077500000000000000000000164611214242626200173540ustar00rootroot00000000000000--------------------------------------------------------------------- -- LuaSOAP test file. -- $Id: test.lua,v 1.6 2009/07/22 19:02:46 tomas Exp $ --------------------------------------------------------------------- local lom = require"lxp.lom" local soap = require"soap" function table.equal (t1, t2) assert (type(t1) == type(t2), string.format ("%s (%s) ~= %s (%s)", type(t1), tostring(t1), type(t2), tostring(t2))) for i, v1 in pairs (t1) do local v2 = t2[i] local tv1 = type(v1) if tv1 == "table" then local ok, err = table.equal (v1, v2) if not ok then return false, err end elseif v1 ~= v2 then return false, string.format ("%s ~= %s", tostring(v1), tostring(v2)) end end return true end local tests = { { namespace = "Some-URI", method = "GetLastTradePrice", entries = { { tag = "symbol", "DEF" }, }, header = { tag = "t:Transaction", attr = { "xmlns:t", "soap:mustUnderstand", ["xmlns:t"] = "some-URI", ["soap:mustUnderstand"] = 1, }, 5, }, xml = [[ 5 DEF ]] }, { namespace = "Some-URI", method = "GetLastTradePriceDetailed", entries = { { tag = "Symbol", "DEF" }, { tag = "Company", "DEF Corp" }, { tag = "Price", 34.1 }, }, xml = [[ DEF DEF Corp 34.1 ]] }, { namespace = "Some-URI", method = "GetLastTradePriceResponse", entries = { { tag = "Price", 34.5 }, }, header = { tag = "t:Transaction", attr = { "xmlns:t", "xsi:type", "mustUnderstand", ["xmlns:t"] = "some-URI", ["xsi:type"] = "xsd:int", ["mustUnderstand"] = 1, }, 5, }, xml = [[ 5 34.5 ]] }, { namespace = "Some-URI", method = "GetLastTradePriceResponse", entries = { { tag = "PriceAndVolume", { tag = "LastTradePrice", 34.5, }, { tag = "DayVolume", 10000, }, } }, xml = [[ 34.5 10000 ]] }, { namespace = nil, method = "soap:Fault", entries = { { tag = "faultcode", "soap:MustUnderstand", }, { tag = "faultstring", "SOAP Must Understand Error", }, }, xml = [[ soap:MustUnderstand SOAP Must Understand Error ]] }, { namespace = nil, method = "soap:Fault", entries = { { tag = "faultcode", "soap:Server", }, { tag = "faultstring", "Server Error", }, { tag = "detail", { tag = "e:myfaultdetails", attr = { "xmlns:e", ["xmlns:e"] = "Some-URI", }, { tag = "message", "My application didn't work", }, { tag = "errorcode", 1001, }, }, }, }, xml = [[ soap:Server Server Error My application didn't work 1001 ]] }, { namespace = nil, method = "easyStructTest", entries = { { tag = "stooges", { tag = "curly", attr = { "xsi:type", ["xsi:type"] = "xsd:int", }, -21, }, { tag = "larry", attr = { "xsi:type", ["xsi:type"] = "xsd:int", }, 59, }, { tag = "moe", attr = { "xsi:type", ["xsi:type"] = "xsd:int", }, 11, }, }, }, xml = [[ -21 59 11 ]] }, { namespace = nil, method = "StringEscapingTest", entries = { { tag = "string", " <this was automatically escaped "this was also &automatically &escaped" do not re-escape my & ]] }, } for i, t in ipairs(tests) do local s = soap.encode (t) s = string.gsub (s, "[\n\r\t]", "") local ok, err = lom.parse ([[]]..s) local ds = assert (ok, (err or '').."\non test #"..i..": "..t.method..'\n'..s) t.xml = string.gsub (t.xml, "[\n\r\t]", "") local ok, err = lom.parse ([[]]..t.xml) local dx = assert (ok, (err or '').."\non test #"..i..": "..t.method..'\n'..t.xml..'\n'..s) assert (table.equal (ds, dx)) end print(soap._VERSION, "Ok!")