summaryrefslogtreecommitdiff
path: root/Presence
diff options
context:
space:
mode:
Diffstat (limited to 'Presence')
-rw-r--r--Presence/AdaptServer.hs10
-rw-r--r--Presence/XMPPServer.hs48
2 files changed, 50 insertions, 8 deletions
diff --git a/Presence/AdaptServer.hs b/Presence/AdaptServer.hs
index 2ef07038..3b57266c 100644
--- a/Presence/AdaptServer.hs
+++ b/Presence/AdaptServer.hs
@@ -3,7 +3,7 @@
3module AdaptServer where 3module AdaptServer where
4 4
5import Data.IORef 5import Data.IORef
6-- import Debug.Trace 6import Debug.Trace
7import Data.HList 7import Data.HList
8-- import Network.Socket (Socket) 8-- import Network.Socket (Socket)
9import qualified Data.ByteString.Lazy.Char8 as L 9import qualified Data.ByteString.Lazy.Char8 as L
@@ -14,7 +14,7 @@ adaptStartCon start sock st = do
14 st' <- start sock st 14 st' <- start sock st
15 return (HCons rsRef st') 15 return (HCons rsRef st')
16 16
17adaptDoCon (dropTill,lex,parse) g st bs cont = do 17adaptDoCon showlex (dropTill,lex,parse) g st bs cont = do
18 putStrLn $ "packet: " ++ show bs 18 putStrLn $ "packet: " ++ show bs
19 let (HCons rsRef st') = st 19 let (HCons rsRef st') = st
20 rs <- readIORef rsRef 20 rs <- readIORef rsRef
@@ -27,15 +27,15 @@ adaptDoCon (dropTill,lex,parse) g st bs cont = do
27 case e of 27 case e of
28 Left err -> if null rs' 28 Left err -> if null rs'
29 then contR "" () 29 then contR "" ()
30 else -- trace ("parse error "++show (err,bs,lexemes,rs')) $ do 30 else trace ("parse error "++show (err,bs,showlex lexemes,showlex rs')) $ do
31 contR rem () 31 contR rem ()
32 Right e -> do 32 Right e -> do
33 -- writeIORef rsRef rs' 33 -- writeIORef rsRef rs'
34 g st' e (\() -> loop (dropTill rem rs') rs') 34 g st' e (\() -> do { putStrLn ("LOOP "++showlex rs'); loop (dropTill rem rs') rs' })
35 loop rem [] = contR "" () 35 loop rem [] = contR "" ()
36 let buf = rs <++> bs 36 let buf = rs <++> bs
37 when (L.length buf < 8192) 37 when (L.length buf < 8192)
38 (loop buf (lex buf)) 38 (loop buf (lex buf))
39 39
40 40
41adaptServer (dropTill,lex,parse) (startCon,doCon) = (adaptStartCon startCon, adaptDoCon (dropTill,lex,parse) doCon) 41adaptServer showlex (dropTill,lex,parse) (startCon,doCon) = (adaptStartCon startCon, adaptDoCon showlex (dropTill,lex,parse) doCon)
diff --git a/Presence/XMPPServer.hs b/Presence/XMPPServer.hs
index aa3140e5..c9decd6c 100644
--- a/Presence/XMPPServer.hs
+++ b/Presence/XMPPServer.hs
@@ -6,6 +6,7 @@
6-- {-# LANGUAGE GADTs #-} 6-- {-# LANGUAGE GADTs #-}
7module XMPPServer where -- ( listenForXmppClients ) where 7module XMPPServer where -- ( listenForXmppClients ) where
8 8
9import Data.Char (isSpace)
9import Todo 10import Todo
10import Data.HList.TypeEqGeneric1() 11import Data.HList.TypeEqGeneric1()
11import Data.HList.TypeCastGeneric1() 12import Data.HList.TypeCastGeneric1()
@@ -412,20 +413,61 @@ runTryParse (Try p) = p
412mapRight f (Right x,ls) = (Right (f x),ls) 413mapRight f (Right x,ls) = (Right (f x),ls)
413mapRight f (Left y,ls) = (Left y ,ls) 414mapRight f (Left y,ls) = (Left y ,ls)
414 415
416dropLeadingSpace toks = dropWhile space toks
417 where
418 space (_,TokFreeText cs) = all isSpace cs
419 space _ = False
420
415xmppParse :: [(Posn, TokenT)] -> (Either String XmppObject, [(Posn, TokenT)]) 421xmppParse :: [(Posn, TokenT)] -> (Either String XmppObject, [(Posn, TokenT)])
416xmppParse ls = runTryParse $ do 422xmppParse ls = runTryParse $ do
417 let xml :: (t -> b) -> XParser t -> (Either String b, [(Posn, TokenT)]) 423 let xml :: (t -> b) -> XParser t -> (Either String b, [(Posn, TokenT)])
418 xml tag = mapRight tag . flip xmlParseWith ls 424 xml tag = mapRight tag . flip xmlParseWith (dropLeadingSpace ls)
419 Try . xml Element $ element 425 Try . xml Element $ element
420 Try . xml OpenTag $ elemOpenTag 426 Try . xml OpenTag $ elemOpenTag
421 Try . xml CloseTag $ elemCloseTag streamName 427 Try . xml CloseTag $ elemCloseTag streamName
422 Try . xml ProcessingInstruction $ processinginstruction 428 Try . xml ProcessingInstruction $ processinginstruction
429
430
431showTokenT TokCommentOpen = "<!--"
432showTokenT TokCommentClose = "-->"
433showTokenT TokPIOpen = "<?"
434showTokenT TokPIClose = "?>"
435showTokenT TokSectionOpen = "<!["
436showTokenT TokSectionClose = "]]>"
437showTokenT TokSpecialOpen = "<!"
438showTokenT TokEndOpen = "</"
439showTokenT TokEndClose = "/>"
440showTokenT TokAnyOpen = "<"
441showTokenT TokAnyClose = ">"
442showTokenT TokSqOpen = "["
443showTokenT TokSqClose = "]"
444showTokenT TokEqual = "="
445showTokenT TokQuery = "?"
446showTokenT TokStar = "*"
447showTokenT TokPlus = "+"
448showTokenT TokAmp = "&"
449showTokenT TokSemi = ";"
450showTokenT TokHash = "#"
451showTokenT TokBraOpen = "("
452showTokenT TokBraClose = ")"
453showTokenT TokPipe = "|"
454showTokenT TokPercent = "%"
455showTokenT TokComma = ","
456showTokenT TokQuote = "' or \""
457showTokenT TokNull = "(null)"
458showTokenT (TokError s) = "TokError "++ Prelude.show s
459showTokenT (TokSection s) = "TokSection "++Prelude.show s
460showTokenT (TokSpecial s) = "TokSpecial "++Prelude.show s
461showTokenT (TokName s) = "TokName "++Prelude.show s
462showTokenT (TokFreeText s) = "TokFreeText "++s
463
464showtoks ts = Prelude.show $ map (showTokenT . snd) ts
423 465
424 466
425listenForXmppClients session_factory port st = do 467listenForXmppClients session_factory port st = do
426 -- standard port: 5222 468 -- standard port: 5222
427 let (start,dopkt) = 469 let (start,dopkt) =
428 adaptServer ( dropTill 470 adaptServer showtoks ( dropTill
429 , xmlLexPartial "local-client" . unpack 471 , xmlLexPartial "local-client" . unpack
430 , xmppParse) 472 , xmppParse)
431 (startCon session_factory,doCon) 473 (startCon session_factory,doCon)
@@ -481,7 +523,7 @@ xmlLexPartial name cs =
481listenForRemotePeers session_factory port st = do 523listenForRemotePeers session_factory port st = do
482 -- standard port: 5269 524 -- standard port: 5269
483 let (start,dopkt) = 525 let (start,dopkt) =
484 adaptServer ( dropTill 526 adaptServer showtoks ( dropTill
485 , xmlLexPartial "remote-inbound" . unpack 527 , xmlLexPartial "remote-inbound" . unpack
486 , xmppParse) 528 , xmppParse)
487 (startPeer session_factory,doPeer) 529 (startPeer session_factory,doPeer)