test.lua
changeset 53 2dcfa81100e4
parent 29 e86ee1f4227d
child 57 37ed3c7ac1b6
equal deleted inserted replaced
52:c7031f15125d 53:2dcfa81100e4
    15 
    15 
    16 -- Note, this requires glib module, that is not released yet
    16 -- Note, this requires glib module, that is not released yet
    17 -- (and, probably, will not be released ever), thus, this
    17 -- (and, probably, will not be released ever), thus, this
    18 -- code is provided only as example.
    18 -- code is provided only as example.
    19 
    19 
    20 require 'glib'
    20 local g  = require 'glib'
    21 local lm = require 'lm'
    21 local lm = require 'lm'
    22 
    22 
    23 g.log.handler (
    23 g.log.handler (
    24 	function ( domain, lvl, mesg )
    24 	function ( domain, lvl, mesg )
    25 		print ( mesg )
    25 		print ( mesg )
    26 	end )
    26 	end )
    27 
    27 
    28 sent = false
    28 local sent = false
    29 
    29 
    30 username, server = arg[1]:match ( '(.+)@(.+)' )
    30 local username, server = arg[1]:match ( '(.+)@(.+)' )
    31 password         = arg[2]
    31 local password         = arg[2]
    32 recipient        = arg[3] or arg[1]
    32 local recipient        = arg[3] or arg[1]
    33 fingerprint      = arg[4] or '01:23:45:67:89:ab:cd:ef:fe:dc:ba:98:76:54:32:10'
    33 local fingerprint      = arg[4] or '01:23:45:67:89:ab:cd:ef:fe:dc:ba:98:76:54:32:10'
       
    34 
       
    35 print ( ("Connectng to %s with username %s\nWill contact %s."):format ( server, username, recipient ) )
    34 
    36 
    35 --[[
    37 --[[
    36 -- What's goes on, pretty close to C api,
    38 -- What's goes on, pretty close to C api,
    37 -- but already some luxury...
    39 -- but already some luxury...
    38 you_need_your_own_context = true
    40 you_need_your_own_context = true
    95 
    97 
    96 --]]
    98 --]]
    97 
    99 
    98 -- Shortened version with convenience lua functions:
   100 -- Shortened version with convenience lua functions:
    99 
   101 
   100 conn = lm.connect {
   102 local conn = lm.connect {
   101 	server = server,
   103 	server = server,
   102 	port   = 5223,
   104 	port   = 5222,
   103 	ssl    = {
   105 	ssl    = {
   104 		fingerprint = fingerprint,
   106 		fingerprint = fingerprint,
   105 		validate    = false,
   107 		validate    = false,
   106 	},
   108 	},
   107 	username = username,
   109 	username = username,
   131 				end )
   133 				end )
   132 			print ( 'sent' )
   134 			print ( 'sent' )
   133 		end,
   135 		end,
   134 }
   136 }
   135 
   137 
   136 cont = g.main_context.default ()
   138 local cont = g.main_context.default ()
   137 print ( 'Entering main loop...' )
   139 print ( 'Entering main loop...' )
   138 while not sent do
   140 while not sent do
   139 	cont:iteration ( true )
   141 	cont:iteration ( true )
   140 end
   142 end
   141 
   143