Software /
code /
verse
Changeset
0:caf260adc453
Beginning of new verse
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 04 Aug 2009 00:10:45 +0100 |
parents | |
children | 1:7c8d0a2fc004 |
files | init.lua libs/encodings.lua libs/logger.lua squishy |
diffstat | 4 files changed, 91 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/init.lua Tue Aug 04 00:10:45 2009 +0100 @@ -0,0 +1,59 @@ + + +local server = require "server"; +local xmlhandlers = require "xmlhandlers"; +local jid = require "jid"; +local jid_split = jid.split; + +module("verse", package.seeall); +local verse = _M; + +local stream = {}; +stream.__index = stream; + +function verse.new() + return setmetatable({}, stream); +end + +function verse.loop() + return server.loop(); +end + +function stream:connect(jid, pass) + self.jid, self.password = jid, pass; + self.username, self.host, self.resource = jid_split(jid); + local conn, err = server.addclient(self.connect_host or self.host, tonumber(self.connect_port) or 5222, new_listener(self), "*a"); + + if not conn then + return nil, err; + end + + self.conn = conn; +end + +function new_listener(stream) + local conn_listener = {}; + + function conn_listener.incoming(conn, data) + if not stream.connected then + stream.connected = true; + stream.send = function (stream, data) stream:debug("Sending data: "..tostring(data)); return conn.write(tostring(data)); end; + stream:event("connected"); + end + if data then + stream:event("incoming-raw", data); + end + end + + function conn_listener.disconnect(conn, err) + stream.connected = false; + stream:event("disconnected", { reason = err }); + end + + return conn_listener; +end + + +local log = require "util.logger".init("verse"); + +return verse;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libs/encodings.lua Tue Aug 04 00:10:45 2009 +0100 @@ -0,0 +1,5 @@ +module "encodings" + +stringprep = {}; + +return _M;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libs/logger.lua Tue Aug 04 00:10:45 2009 +0100 @@ -0,0 +1,10 @@ +local print = print +module "logger" + +function init(name) + return function (level, message) + print(level, message); + end +end + +return _M;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/squishy Tue Aug 04 00:10:45 2009 +0100 @@ -0,0 +1,17 @@ +Output "verse2.lua" + +-- Verse-specific versions of libraries +Module "util.encodings" "libs/encodings.lua" +Module "util.logger" "libs/logger.lua" + +-- Prosody libraries +AutoFetchURL "http://prosody.im/tip/?" + +Module "util.stanza" "util/stanza.lua" +Module "util.termcolours" "util/termcolours.lua" +Module "server" "net/server.lua" +Module "xmlhandlers" "core/xmlhandlers.lua" +Module "jid" "util/jid.lua" + +-- Main verse file +Main "init.lua"