lm.lua
changeset 66 a40beb82130c
parent 59 19cfaceda6bb
equal deleted inserted replaced
65:72ffcf688664 66:a40beb82130c
   194 	else
   194 	else
   195 		error "at least server name parameter required"
   195 		error "at least server name parameter required"
   196 	end
   196 	end
   197 end
   197 end
   198 
   198 
   199 -- TODO: multiple nodes with same name
   199 function lm.message_node.parse ( node )
   200 function lm.message_node.parse ( node, r )
   200 	-- attributes
       
   201 	local r = node:attributes ()
       
   202 	-- node value (text)
       
   203 	local value = n:value ()
       
   204 	if value then
       
   205 		s[1] = value
       
   206 	end
       
   207 	-- children nodes
   201 	local n = node:child ()
   208 	local n = node:child ()
   202 	while n do
   209 	for n in node:children () do
   203 		local name = n:name ()
   210 		local name = n:name ()
   204 		r[name] = { }
   211 		if type ( r[name] ) ~= 'table' then
   205 		local value = n:value ()
   212 			r[name] = { }
   206 		if value then
   213 		end
   207 			r[name][1] = value
   214 		table.insert ( r[name], lm.message_node.parse ( n ) )
   208 		end
   215 	end
   209 		lm.message_node.parse ( n, r[name] )
   216 	return r
   210 		n = n:next ()
   217 end
   211 	end
   218 
   212 end
       
   213 
       
   214 -- There are NO WAY to get a list of node attributes,
       
   215 -- except brute force...
       
   216 function lm.message.parse ( message )
   219 function lm.message.parse ( message )
       
   220 	local r = lm.message_node.parse ( message )
       
   221 	-- message type we treat in a special way
   217 	local mtype, subtype = message:type ()
   222 	local mtype, subtype = message:type ()
   218 	if subtype then
   223 	if subtype then
   219 		mtype = mtype .. '-' .. subtype
   224 		mtype = mtype .. '-' .. subtype
   220 	end
   225 	end
   221 	local r = { mtype = mtype }
   226 	r['mtype'] = mtype
   222 	local value = message:value ()
       
   223 	if value then
       
   224 		r[1] = value
       
   225 	end
       
   226 	lm.message_node.parse ( message, r )
       
   227 	return r
   227 	return r
   228 end
   228 end
   229 
   229 
   230 -- The same table, as for lm.connection.create, but with few more fields:
   230 -- The same table, as for lm.connection.create, but with few more fields:
   231 -- * ssl.validate - boolean
   231 -- * ssl.validate - boolean