equal
deleted
inserted
replaced
1 |
1 |
2 require ( 'loudmouth' ) |
2 lm = 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 |
8 error ( "arguments should be in a table" ) |
8 error "arguments should be in a table" |
9 end |
9 end |
10 local p = lm.proxy.new () |
10 local p = lm.proxy.new () |
11 if a.server then |
11 if a.server then |
12 p:server ( a.server ) |
12 p:server ( a.server ) |
13 end |
13 end |
29 -- argument is a table with two keys: |
29 -- argument is a table with two keys: |
30 -- callback and fingerprint |
30 -- callback and fingerprint |
31 function lm.ssl.create ( a ) |
31 function lm.ssl.create ( a ) |
32 if not lm.ssl.supported () then |
32 if not lm.ssl.supported () then |
33 -- XXX |
33 -- XXX |
34 -- error ( "ssl is not supported by your loudmouth library" ) |
34 -- error "ssl is not supported by your loudmouth library" |
35 return nil |
35 return nil |
36 end |
36 end |
37 local fp, cb |
37 local fp, cb |
38 local st = type ( a ) |
38 local st = type ( a ) |
39 if st == "table" then |
39 if st == "table" then |
42 elseif st == "function" then |
42 elseif st == "function" then |
43 cb = a |
43 cb = a |
44 elseif st == "string" then |
44 elseif st == "string" then |
45 fp = a |
45 fp = a |
46 elseif st ~= "nil" then |
46 elseif st ~= "nil" then |
47 error ( "unexpected type of argument" ) |
47 error "unexpected type of argument" |
48 end |
48 end |
49 if fp then |
49 if fp then |
50 if cb then |
50 if cb then |
51 return lm.ssl.new ( fp, cb ) |
51 return lm.ssl.new ( fp, cb ) |
52 else |
52 else |
78 if at == "string" then |
78 if at == "string" then |
79 return lm.connection.new ( a ) |
79 return lm.connection.new ( a ) |
80 elseif at == "table" then |
80 elseif at == "table" then |
81 local server = a.server |
81 local server = a.server |
82 if not server then |
82 if not server then |
83 error ( "server name parameter required" ) |
83 error "server name parameter required" |
84 end |
84 end |
85 |
85 |
86 -- create connection object |
86 -- create connection object |
87 local c |
87 local c |
88 if a.context then |
88 if a.context then |
206 }, |
206 }, |
207 } |
207 } |
208 --]] |
208 --]] |
209 function lm.message.create ( a ) |
209 function lm.message.create ( a ) |
210 if type ( a ) ~= "table" then |
210 if type ( a ) ~= "table" then |
211 error ( "table expected as argument" ) |
211 error "table expected as argument" |
212 end |
212 end |
213 if not a.mtype or not a.to then |
213 if not a.mtype or not a.to then |
214 error ( "you must specify message type and destination" ) |
214 error "you must specify message type and destination" |
215 end |
215 end |
216 local mtype, subtype = a.mtype:match ( "(.-)%-(.+)" ) |
216 local mtype, subtype = a.mtype:match ( "(.-)%-(.+)" ) |
217 local m |
217 local m |
218 if not mtype then |
218 if not mtype then |
219 m = lm.message.new ( a.to, a.mtype ) |
219 m = lm.message.new ( a.to, a.mtype ) |
265 -- username |
265 -- username |
266 -- password |
266 -- password |
267 -- resource |
267 -- resource |
268 function lm.connect ( a ) |
268 function lm.connect ( a ) |
269 if type ( a ) ~= "table" then |
269 if type ( a ) ~= "table" then |
270 error ( "table expected as argument" ) |
270 error "table expected as argument" |
271 end |
271 end |
272 if a.ssl then |
272 if a.ssl then |
273 if a.ssl.validate and not a.ssl.callback then |
273 if a.ssl.validate and not a.ssl.callback then |
274 a.ssl.callback = |
274 a.ssl.callback = |
275 function ( obj, status ) |
275 function ( obj, status ) |