--- a/lm.lua Sat Mar 05 14:57:58 2016 +0200
+++ b/lm.lua Sat Mar 05 15:43:04 2016 +0200
@@ -1,4 +1,4 @@
---[[ Copyright 2009 Myhailo Danylenko
+--[[ Copyright 2009-2016 Myhailo Danylenko
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -15,8 +15,12 @@
local lm = require 'loudmouth'
--- argument is a table with keys,
--- corresponding to method names.
+-- Argument is a table with keys:
+-- * server - server name to connect to
+-- * port - port to connect to
+-- * type - proxy type
+-- * username - uername to authenticate on proxy
+-- * password - password to authenticate with
function lm.proxy.create ( a )
if type ( a ) ~= "table" then
error "arguments should be in a table"
@@ -40,21 +44,35 @@
return p
end
--- argument is a table with two keys:
--- callback and fingerprint
+-- Argument is a table with keys:
+-- * fingerprint - fingerprint string
+-- * callback - ssl error callback
+-- * tls - string - one of "on", "required", "off" (default)
+-- * ca_path - path to trusted certificates
+-- * cipher_list - list of allowed ciphers to ues
function lm.ssl.create ( a )
if not lm.ssl.supported () then
-- XXX
-- error "ssl is not supported by your loudmouth library"
return nil
end
- local fp, cb, ut, rt
+ local fp, cb, ut, rt, ca, cl
local st = type ( a )
if st == "table" then
fp = a.fingerprint
cb = a.callback
- ut = a.tls
- rt = a.require_tls
+ ca = a.ca_path
+ cl = a.cipher_list
+ tl = a.tls
+ if tl ~= nil then
+ if tl == "on" then
+ ut = true
+ rt = false
+ elseif tl == "required" then
+ ut = true
+ rt = true
+ end
+ end
elseif st == "function" then
cb = a
elseif st == "string" then
@@ -76,24 +94,28 @@
ssl = lm.ssl.new ()
end
end
+ if ca ~= nil then
+ ssl:ca_path ( ca )
+ end
+ if cl ~= nil then
+ ssl:cipher_list ( cl )
+ end
if ut ~= nil then
ssl:tls ( ut, rt )
end
return ssl
end
--- basically, it just provides a way
--- to initialize many parameters at once.
--- keys in a table correspond to methods
--- of connection object, except for handlers,
--- where format is {
--- "type/priority" = function/object,
--- ...
--- }
--- two extra keys - server and context.
--- ssl and proxy objects can either be objects
--- or tables, directly passed to corresponding
--- create routine.
+-- Argument is a table with keys:
+-- * server - server name
+-- * context - glib main context
+-- * port - server port
+-- * jid - jid to connect with
+-- * keep_alive_rate - rate of keep alive packets
+-- * proxy - lm.proxy object or table
+-- * ssl - lm.ssl object or table
+-- * ondisconnect - disconnect callback
+-- * handlers - table with { "type/priority" = function/object } mapping
function lm.connection.create ( a )
local at = type (a)
if at == "string" then
@@ -205,14 +227,14 @@
return r
end
--- the same table, as for lm.connection.create, but with few more fields:
--- ssl.validate - boolean
--- preopen - callback to call after connection creation but before opening (to install log handler, for example)
--- onopen - callback to call after connection is established, but before authentication
--- onconnect - callback to call after connection will be established
--- username
--- password
--- resource
+-- The same table, as for lm.connection.create, but with few more fields:
+-- * ssl.validate - boolean
+-- * preopen - callback to call after connection creation but before opening (to install log handler, for example)
+-- * onopen - callback to call after connection is established, but before authentication
+-- * onconnect - callback to call after connection will be established
+-- * username - username to authenticate with
+-- * password - password to authenticate with
+-- * resource - jabber resource to use
function lm.connect ( a )
if type ( a ) ~= "table" then
error "table expected as argument"