examples/iq.lua
author Myhailo Danylenko <isbear@ukrpost.net>
Mon, 23 Mar 2009 05:06:15 +0200
changeset 61 5182f466da7d
parent 49 95f3bf77c598
child 64 bf7521ed96eb
permissions -rw-r--r--
Fix activity
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
43
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     1
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     2
-- CORE, IQ
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     3
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     4
-- library
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     5
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     6
require 'lm'
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     7
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     8
-- public
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
     9
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    10
iq = { }
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    11
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    12
function iq.send ( conn, to, smtype, data, success, fail )
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    13
	data.mtype = 'iq-' .. smtype
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    14
	data.to    = to
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    15
	conn:send ( lm.message.create ( data ),
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    16
		function ( conn, mess )
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    17
			local mtype, smtype = mess:type ()
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    18
			if smtype == 'result' then
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    19
				success ( mess )
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    20
			elseif smtype == 'error' then
49
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 43
diff changeset
    21
				fail ( mess:child( 'error' ):children():name (), mess ) -- FIXME
43
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    22
			else
49
95f3bf77c598 Forms in modular way
Myhailo Danylenko <isbear@ukrpost.net>
parents: 43
diff changeset
    23
				fail ( mess:xml (), mess )
43
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    24
				return false
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    25
			end
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    26
			return true
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    27
		end )
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    28
end
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    29
7c22b1f2c6e5 Iq separation
Myhailo Danylenko <isbear@ukrpost.net>
parents:
diff changeset
    30
-- vim: se ts=4: --