Browse Source

fix jidParts (would not parse domain/resource without localpart)

master
Philipp Balzarek 12 years ago
parent
commit
387d5f885f
  1. 51
      source/Network/Xmpp/Types.hs

51
source/Network/Xmpp/Types.hs

@ -69,7 +69,7 @@ module Network.Xmpp.Types
) )
where where
import Control.Applicative ((<|>), many) import Control.Applicative ((<$>), (<|>), many)
import Control.Concurrent.STM import Control.Concurrent.STM
import Control.Exception import Control.Exception
import Control.Monad.Error import Control.Monad.Error
@ -914,48 +914,23 @@ domainpart = domainpart_
resourcepart :: Jid -> Maybe Text resourcepart :: Jid -> Maybe Text
resourcepart = resourcepart_ resourcepart = resourcepart_
-- Parses a JID string and returns its three parts. It performs no validation
-- or transformations.
jidParts :: AP.Parser (Maybe Text, Text, Maybe Text) jidParts :: AP.Parser (Maybe Text, Text, Maybe Text)
jidParts = do jidParts = do
-- Read until we reach an '@', a '/', or EOF. maybeLocalPart <- Just <$> localPart <|> return Nothing
a <- AP.takeWhile1 (AP.notInClass ['@', '/']) domainPart <- AP.takeWhile1 (AP.notInClass ['@', '/'])
-- Case 1: We found an '@', and thus the localpart. At least the domainpart maybeResourcePart <- Just <$> resourcePart <|> return Nothing
-- is remaining. Read the '@' and until a '/' or EOF. AP.endOfInput
do return (maybeLocalPart, domainPart, maybeResourcePart)
b <- domainPartP
-- Case 1A: We found a '/' and thus have all the JID parts. Read the '/'
-- and until EOF.
do
c <- resourcePartP -- Parse resourcepart
return (Just a, b, Just c)
-- Case 1B: We have reached EOF; the JID is in the form
-- localpart@domainpart.
<|> do
AP.endOfInput
return (Just a, b, Nothing)
-- Case 2: We found a '/'; the JID is in the form
-- domainpart/resourcepart.
<|> do
b' <- resourcePartP
AP.endOfInput
return (Nothing, a, Just b')
-- Case 3: We have reached EOF; we have an JID consisting of only a
-- domainpart.
<|> do
AP.endOfInput
return (Nothing, a, Nothing)
where where
-- Read an '@' and everything until a '/'. localPart = do
domainPartP :: AP.Parser Text bytes <- AP.takeWhile1 (AP.notInClass ['@', '/'])
domainPartP = do
_ <- AP.char '@' _ <- AP.char '@'
AP.takeWhile1 (/= '/') return bytes
-- Read everything until a '/'. resourcePart = do
resourcePartP :: AP.Parser Text
resourcePartP = do
_ <- AP.char '/' _ <- AP.char '/'
AP.takeText AP.takeWhile1 (AP.notInClass ['@', '/'])
-- The `nodeprep' StringPrep profile. -- The `nodeprep' StringPrep profile.
nodeprepProfile :: SP.StringPrepProfile nodeprepProfile :: SP.StringPrepProfile

Loading…
Cancel
Save