diff options
-rw-r--r-- | Presence/AdaptServer.hs | 10 | ||||
-rw-r--r-- | Presence/XMPPServer.hs | 48 |
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 @@ | |||
3 | module AdaptServer where | 3 | module AdaptServer where |
4 | 4 | ||
5 | import Data.IORef | 5 | import Data.IORef |
6 | -- import Debug.Trace | 6 | import Debug.Trace |
7 | import Data.HList | 7 | import Data.HList |
8 | -- import Network.Socket (Socket) | 8 | -- import Network.Socket (Socket) |
9 | import qualified Data.ByteString.Lazy.Char8 as L | 9 | import 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 | ||
17 | adaptDoCon (dropTill,lex,parse) g st bs cont = do | 17 | adaptDoCon 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 | ||
41 | adaptServer (dropTill,lex,parse) (startCon,doCon) = (adaptStartCon startCon, adaptDoCon (dropTill,lex,parse) doCon) | 41 | adaptServer 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 #-} |
7 | module XMPPServer where -- ( listenForXmppClients ) where | 7 | module XMPPServer where -- ( listenForXmppClients ) where |
8 | 8 | ||
9 | import Data.Char (isSpace) | ||
9 | import Todo | 10 | import Todo |
10 | import Data.HList.TypeEqGeneric1() | 11 | import Data.HList.TypeEqGeneric1() |
11 | import Data.HList.TypeCastGeneric1() | 12 | import Data.HList.TypeCastGeneric1() |
@@ -412,20 +413,61 @@ runTryParse (Try p) = p | |||
412 | mapRight f (Right x,ls) = (Right (f x),ls) | 413 | mapRight f (Right x,ls) = (Right (f x),ls) |
413 | mapRight f (Left y,ls) = (Left y ,ls) | 414 | mapRight f (Left y,ls) = (Left y ,ls) |
414 | 415 | ||
416 | dropLeadingSpace toks = dropWhile space toks | ||
417 | where | ||
418 | space (_,TokFreeText cs) = all isSpace cs | ||
419 | space _ = False | ||
420 | |||
415 | xmppParse :: [(Posn, TokenT)] -> (Either String XmppObject, [(Posn, TokenT)]) | 421 | xmppParse :: [(Posn, TokenT)] -> (Either String XmppObject, [(Posn, TokenT)]) |
416 | xmppParse ls = runTryParse $ do | 422 | xmppParse 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 | |||
431 | showTokenT TokCommentOpen = "<!--" | ||
432 | showTokenT TokCommentClose = "-->" | ||
433 | showTokenT TokPIOpen = "<?" | ||
434 | showTokenT TokPIClose = "?>" | ||
435 | showTokenT TokSectionOpen = "<![" | ||
436 | showTokenT TokSectionClose = "]]>" | ||
437 | showTokenT TokSpecialOpen = "<!" | ||
438 | showTokenT TokEndOpen = "</" | ||
439 | showTokenT TokEndClose = "/>" | ||
440 | showTokenT TokAnyOpen = "<" | ||
441 | showTokenT TokAnyClose = ">" | ||
442 | showTokenT TokSqOpen = "[" | ||
443 | showTokenT TokSqClose = "]" | ||
444 | showTokenT TokEqual = "=" | ||
445 | showTokenT TokQuery = "?" | ||
446 | showTokenT TokStar = "*" | ||
447 | showTokenT TokPlus = "+" | ||
448 | showTokenT TokAmp = "&" | ||
449 | showTokenT TokSemi = ";" | ||
450 | showTokenT TokHash = "#" | ||
451 | showTokenT TokBraOpen = "(" | ||
452 | showTokenT TokBraClose = ")" | ||
453 | showTokenT TokPipe = "|" | ||
454 | showTokenT TokPercent = "%" | ||
455 | showTokenT TokComma = "," | ||
456 | showTokenT TokQuote = "' or \"" | ||
457 | showTokenT TokNull = "(null)" | ||
458 | showTokenT (TokError s) = "TokError "++ Prelude.show s | ||
459 | showTokenT (TokSection s) = "TokSection "++Prelude.show s | ||
460 | showTokenT (TokSpecial s) = "TokSpecial "++Prelude.show s | ||
461 | showTokenT (TokName s) = "TokName "++Prelude.show s | ||
462 | showTokenT (TokFreeText s) = "TokFreeText "++s | ||
463 | |||
464 | showtoks ts = Prelude.show $ map (showTokenT . snd) ts | ||
423 | 465 | ||
424 | 466 | ||
425 | listenForXmppClients session_factory port st = do | 467 | listenForXmppClients 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 = | |||
481 | listenForRemotePeers session_factory port st = do | 523 | listenForRemotePeers 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) |