lm.lua
changeset 7 5db1448eb857
parent 6 90073cbb535d
child 12 63f06a23c235
equal deleted inserted replaced
6:90073cbb535d 7:5db1448eb857
     1 
     1 
     2 lm = require 'loudmouth'
     2 require 'loudmouth'
     3 
     3 
     4 -- argument is a table with keys,
     4 -- argument is a table with keys,
     5 -- corresponding to method names.
     5 -- corresponding to method names.
     6 function lm.proxy.create ( a )
     6 function lm.proxy.create ( a )
     7 	if type ( a ) ~= "table" then
     7 	if type ( a ) ~= "table" then
   147 			end
   147 			end
   148 		end
   148 		end
   149 
   149 
   150 		return c
   150 		return c
   151 	else
   151 	else
   152 		error ( "at least server name parameter required" )
   152 		error "at least server name parameter required"
   153 	end
   153 	end
   154 end
   154 end
   155 
   155 
   156 -- recursively fills a node, see lm.message.create
   156 -- recursively fills a node, see lm.message.create
   157 function lm.message_node.fill ( n, a )
   157 function lm.message_node.fill ( n, a )
   220 	else
   220 	else
   221 		m = lm.message.new ( a.to, mtype, subtype )
   221 		m = lm.message.new ( a.to, mtype, subtype )
   222 	end
   222 	end
   223 	a.to = nil
   223 	a.to = nil
   224 	a.mtype = nil
   224 	a.mtype = nil
   225 	lm.message_node.fill ( m:node(), a )
   225 	lm.message_node.fill ( m, a )
   226 	return m
   226 	return m
   227 end
   227 end
   228 
   228 
   229 -- TODO: multiple nodes with same name
   229 -- TODO: multiple nodes with same name
   230 function lm.message_node.parse ( node, r )
   230 function lm.message_node.parse ( node, r )
   242 end
   242 end
   243 
   243 
   244 -- There are NO WAY to get a list of node attributes,
   244 -- There are NO WAY to get a list of node attributes,
   245 -- except brute force...
   245 -- except brute force...
   246 function lm.message.parse ( message )
   246 function lm.message.parse ( message )
   247 	local node = message:node ()
       
   248 	local mtype, subtype = message:type ()
   247 	local mtype, subtype = message:type ()
   249 	if subtype then
   248 	if subtype then
   250 		mtype = mtype .. '-' .. subtype
   249 		mtype = mtype .. '-' .. subtype
   251 	end
   250 	end
   252 	local r = { mtype = mtype }
   251 	local r = { mtype = mtype }
   253 	local value = node:value ()
   252 	local value = message:value ()
   254 	if value then
   253 	if value then
   255 		r[1] = value
   254 		r[1] = value
   256 	end
   255 	end
   257 	lm.message_node.parse ( node, r )
   256 	lm.message_node.parse ( message, r )
   258 	return r
   257 	return r
   259 end
   258 end
   260 
   259 
   261 -- the same table, as for lm.connection.create, but with few more fields:
   260 -- the same table, as for lm.connection.create, but with few more fields:
   262 -- ssl.validate
   261 -- ssl.validate