more mycelium

This commit is contained in:
nik gaffney 2009-04-29 18:46:48 +02:00
parent 3c6f475891
commit 45c4c8254d
3 changed files with 47 additions and 37 deletions

View file

@ -9,12 +9,12 @@
-export([start/2, stop/1]). -export([start/2, stop/1]).
start(_Host, _Opt) -> ok.
stop(_Host) -> ok.
start(_Host, _Opt) -> start(_Host, _Opt) ->
?DEBUG("MYCELIUM LOADING...", []). ?DEBUG("MYCELIUM LOADING...", []).
stop(_Host) -> ok.
?DEBUG("MYCELIUM UNLOADING...", []).
%%-define(PROCNAME, ejabberd_mycelium). %%-define(PROCNAME, ejabberd_mycelium).
%%-define(BOTNAME, mycelium). %%-define(BOTNAME, mycelium).

View file

@ -1,8 +1,14 @@
#lang scheme ;#lang scheme/base
(require "xmpp-dave.ss")
(require scheme/class)
(require openssl) (require openssl)
(require mzlib/os)
(require "sxml/sxml.ss")
(require "ssax/ssax.ss")
(require "xmpp.ss") ;; hostname
(require scheme/tcp) ;; networking
(require openssl) ;; ssl/tls
(require srfi/13)
(require scheme/class)
(define jabberer% (define jabberer%
(class object% (class object%
@ -29,7 +35,8 @@
(define/public (start j p) (define/public (start j p)
(set! jid j) (set! jid j)
(set! pass p) (set! pass p)
(set! thr (thread run))) (run)
#;(set! thr (thread run)))
(define/public (stop) (define/public (stop)
(kill-thread thr)) (kill-thread thr))
@ -37,7 +44,7 @@
(define (run) (define (run)
(with-xmpp-session jid pass (with-xmpp-session jid pass
(set-xmpp-handler 'message message-handler) (set-xmpp-handler 'message message-handler)
(let loop () (let lxop ()
(when (not (null? outgoing)) (when (not (null? outgoing))
(for-each (for-each
(lambda (msg) (lambda (msg)
@ -45,11 +52,13 @@
(xmpp-send (message (car msg) (cadr msg)))) (xmpp-send (message (car msg) (cadr msg))))
outgoing) outgoing)
(set! outgoing '())) (set! outgoing '()))
(sleep 0.5) (sleep 0.05)
(loop)))) #;(lxop))))
(super-new))) (super-new)))
(define j (make-object jabberer%)) (define j (make-object jabberer%))
(send j start "plant0000001@fo.am" "plant0000001") (send j start "plant0000001@fo.am" "plant0000001")
(send j send-msg "dave@fo.am" "woop") (send j send-msg "plant0000003@fo.am" "woop")
(printf "wonk4~n")

View file

@ -74,7 +74,7 @@
(require (planet lizorkin/sxml:2:1/sxml)) ;; encoding xml (require (planet lizorkin/sxml:2:1/sxml)) ;; encoding xml
(require (planet lizorkin/ssax:2:0/ssax)) ;; decoding xml (require (planet lizorkin/ssax:2:0/ssax)) ;; decoding xml
(require mzlib/os) ;; hostname ;(require mzlib/os) ;; hostname
(require mzlib/defmacro) ;; with-xmpp-session macro (require mzlib/defmacro) ;; with-xmpp-session macro
(require scheme/tcp) ;; networking (require scheme/tcp) ;; networking
(require openssl) ;; ssl/tls (require openssl) ;; ssl/tls
@ -265,10 +265,10 @@
;; response handler ;; response handler
(define (xmpp-response-handler in) (define (xmpp-response-handler in)
(thread (lambda () (thread (lambda ()
(let loop () (let lxop ()
(parse-xmpp-response (read-async in)) (parse-xmpp-response (read-async in))
(sleep 0.1) ;; slight delay to avoid a tight loop (sleep 0.1) ;; slight delay to avoid a tight loop
(loop))))) (lxop)))))
;; jid splicing (assuming the jid is in the format user@host/resource) ;; jid splicing (assuming the jid is in the format user@host/resource)
(define (jid-user jid) (define (jid-user jid)
@ -281,7 +281,7 @@
(define (jid-resource jid) (define (jid-resource jid)
(let ((r (jid-resource-0 jid))) (let ((r (jid-resource-0 jid)))
(if (void? r) (gethostname) r))) (if (void? r) "nix" r)))
(define (jid-resource-0 jid) (define (jid-resource-0 jid)
(let ((v (string-index jid #\/))) (let ((v (string-index jid #\/)))
@ -301,10 +301,12 @@
;(printf "sending iO: ~a ~%~%" str) ;(printf "sending iO: ~a ~%~%" str)
(fprintf (xmpp-out-port) "~A~%" str) (flush-output (xmpp-out-port))) (fprintf (xmpp-out-port) "~A~%" str) (flush-output (xmpp-out-port)))
(defmacro with-xmpp-session (jid pass . body) (define-syntax with-xmpp-session
`(let ((host (jid-host ,jid)) (syntax-rules ()
(user (jid-user ,jid)) ((_ jid pass form . forms)
(resource (jid-resource ,jid))) (let ((host (jid-host jid))
(user (jid-user jid))
(resource (jid-resource jid)))
(let-values (((in out) (let-values (((in out)
(ssl-connect host ssl-port 'tls))) (ssl-connect host ssl-port 'tls)))
;;(tcp-connect host port))) ;;(tcp-connect host port)))
@ -315,12 +317,11 @@
(xmpp-send (xmpp-stream host)) (xmpp-send (xmpp-stream host))
(xmpp-send (xmpp-session host)) (xmpp-send (xmpp-session host))
;(starttls in out) ;(starttls in out)
(xmpp-send (xmpp-auth user pass resource))
(xmpp-send (xmpp-auth user ,pass resource))
(xmpp-send (presence)) (xmpp-send (presence))
(xmpp-send (presence #:status "Available")) (xmpp-send (presence #:status "Available"))
,@body (begin form . forms)
(close-output-port out) (close-output-port out)
(close-input-port in))))) (close-input-port in)))))))
) ;; end module ) ;; end module