-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Stomp Parser and Utilities
--
-- The Stomp Protocol specifies message-oriented interoperability.
-- Applications connect to a message broker to send (publish) or receive
-- (subscribe) messages through queues. Interoperating applications do
-- not know the location or internal structure of each other. They see
-- only each other's interfaces, i.e. the messages published and
-- subscribed through the broker. Broker and application use a protocol
-- based on the exchange of commands and other data packets, called
-- frames. The Stompl library provides abstractions over Stomp
-- frames and a Stomp frame parser. It does not implement a client or
-- broker itself, but provides abstractions to libraries and programs
-- doing so. It is used by the Stompl Queue library (stomp-queues). More
-- documentation and a test suite can be found on
-- https://github.com/toschoo/mom/. The Stomp specification can be
-- found at http://stomp.github.com.
@package stompl
@version 0.5.0
-- | Stomp Frames and some useful operations on them
module Network.Mom.Stompl.Frame
-- | This is a frame
data Frame
-- | The frame type identifies, what the Stomp protocol calls
-- command;
--
--
-- - commands sent from application to broker are: Connect, Disconnect,
-- Subscribe, Unsubscribe, Send, Begin, Commit, Abort, Ack, Nack,
-- HeartBeat
-- - commands sent from broker to application are: Connected, Message,
-- Error, HeartBeat
--
data FrameType
-- | Sent by the application to initiate a connection
Connect :: FrameType
-- | Same as Connect, but with STOMP instead of CONNECT
Stomp :: FrameType
-- | Sent by the broker to confirm the connection
Connected :: FrameType
-- | Sent by the application to end the connection
Disconnect :: FrameType
-- | Sent by the application to publish a message in a queue
Send :: FrameType
-- | Sent by the broker to forward a message published in a queue to which
-- the application has subscribed
Message :: FrameType
-- | Sent by the application to subscribe to a queue
Subscribe :: FrameType
-- | Sent by the application to unsubscribe from a queue
Unsubscribe :: FrameType
-- | Sent by the application to start a transaction
Begin :: FrameType
-- | Sent by the application to commit a transaction
Commit :: FrameType
-- | Sent by the application to abort a transaction
Abort :: FrameType
-- | Sent by the application to acknowledge a message
Ack :: FrameType
-- | Sent by the application to negatively acknowledge a message
Nack :: FrameType
-- | Keep-alive message sent by both, application and broker
HeartBeat :: FrameType
-- | Sent by the broker to report an error
Error :: FrameType
-- | Sent by the broker to confirm the receipt of a frame
Receipt :: FrameType
-- | Tuple of (key, value)
type Header = (String, String)
-- | The Frame body is represented as strict ByteString.
type Body = ByteString
-- | Heart-beat configuration; the first Int of the pair represents
-- the frequency in which the sender wants to send heart-beats; the
-- second represents the highest frequency in which the sender can accept
-- heart-beats. The frequency is expressed as the period in milliseconds
-- between two heart-beats. For details on negotiating heart-beats,
-- please refer to the Stomp specification.
type Heart = (Int, Int)
-- | The Stomp version used or accepted by the sender; the first Int
-- is the major version number, the second is the minor. For details on
-- version negotiation, please refer to the Stomp specification.
type Version = (Int, Int)
data AckMode
-- | A successfully sent message is automatically considered ack'd
Auto :: AckMode
-- | The client is expected to explicitly confirm the receipt of a message
-- by sending an Ack frame; all message older than the ack'd
-- message since the last Ack (or the beginning of the session)
-- are implicitly ack'd as well. This is called cumulative ack.
Client :: AckMode
-- | Non-cumulative ack: The client is expected to explicitly confirm the
-- receipt of a message by sending an Ack frame; only the message
-- with the msg-id in the Ack frame is actually ack'd
ClientIndi :: AckMode
-- | check if String represents a valid AckMode
isValidAck :: String -> Bool
-- | Description of a server consisting of name, version and comments
type SrvDesc = (String, String, String)
-- | get name from SrvDesc
getSrvName :: SrvDesc -> String
-- | get version from SrvDesc
getSrvVer :: SrvDesc -> String
-- | get comments from SrvDesc
getSrvCmts :: SrvDesc -> String
-- | make a Connect frame (Application -> Broker). The parameters
-- are:
--
--
-- - User: user to authenticate at the broker.
-- - Passcode: password to authenticate at the broker.
-- - Host: broker's virtual hoast (e.g.
-- stomp.broker.github.org).
-- - HeartBeat: the clients bid in negotiating the
-- heart-beat.
-- - Version: the versions supported by the client.
-- - ClientId: Client identification for persistent connections. Note
-- that the client id is not a standard Stomp feature, but specific to
-- ActiveMQ and other brokers.
-- - Header: List of additional, broker-specific headers
--
mkConnect :: String -> String -> String -> Heart -> [Version] -> String -> [Header] -> Frame
-- | Same as mkConnect, but the result is a "STOMP" frame rather
-- than a "CONNECT" frame
mkStomp :: String -> String -> String -> Heart -> [Version] -> String -> [Header] -> Frame
-- | make a Connect frame (Broker -> Application). The parameters
-- are:
--
--
-- - Session: A unique identifier created by the broker and identifying
-- the session
-- - HeartBeat: The heart-beat agreed by the broker
-- - Version: The version accepted by the broker
-- - SrvDesc: The server description
-- - Header: List of additional, broker-specific headers.
--
mkConnected :: String -> Heart -> Version -> SrvDesc -> [Header] -> Frame
-- | make a Subscribe frame (Application -> Broker). The
-- parameters are:
--
--
-- - Destination: The name of the queue as it is known by the broker
-- and other applications using the queue
-- - AckMode: The Acknowledge Mode for this subscription
-- - Selector: An expression defining those messages that are of actual
-- for client. The Stomp protocol does not define a language for
-- selectors; it is even not entirely clear, where messages are selected:
-- already at the broker, or only by the client. Some brokers provide
-- pre-selection of messages, others do not.
-- - Subscription Id: A unique identifier distinguishing this
-- subscription from others to the same queue. The identifier is defined
-- by the application.
-- - Receipt: A unique identifier defined by the application to request
-- confirmation of receipt of this frame. If no receipt is wanted, the
-- string shall be empty.
-- - Header: List of additional, broker-specific headers.
--
mkSubscribe :: String -> AckMode -> String -> String -> String -> [Header] -> Frame
-- | make an Unsubscribe frame (Application -> Broker). The
-- parameters are:
--
--
-- - Destination: The queue name; either a destination or a
-- subscription id must be given. (According to protocol version 1.1, the
-- subscription id is mandatory on both, Subscribe and
-- Unsubscribe.)
-- - Subscription Id: The subscription identifier (see
-- mkSubscribe)
-- - Receipt: The receipt (see mkSubscribe)
-- - Header: Additional, broker-specific headers
--
mkUnsubscribe :: String -> String -> String -> [Header] -> Frame
-- | make a Send frame (Application -> Broker). The parameters
-- are:
--
--
-- - Destination: The name of the queue where the message should be
-- published
-- - Transaction: A unique identifier indicating a running transaction;
-- if sent with a transaction, the message will not be delivered to
-- subscribing applications, before the transaction is committed. If the
-- Send is not part of a transaction, the string shall be
-- empty.
-- - Receipt: A receipt (see mkSubscribe for details)
-- - Type: The content type of the payload message as MIME
-- Type
-- - Length: The length of the type in bytes
-- - Header: List of additional headers; Stomp protocol requires
-- that user-specified headers are passed through to subscribing
-- applications. These headers may, for instance, be use by selectors to
-- select messages.
-- - Body: The payload message
--
mkSend :: String -> String -> String -> Type -> Int -> [Header] -> Body -> Frame
-- | make a Message frame (Broker -> Application). The parameters
-- are:
--
--
-- - Subscription Id: The message was sent because the application
-- subscribed to the queue with this subscription id (see
-- mkSubscribe).
-- - Destination: The name of the queue, in wich the message was
-- published.
-- - Message Id: A unique message identifier, defined by the
-- broker
-- - Type: The type of the playload as MIME Type
-- - Length: The length of the payload in bytes
-- - Header: A list of user-defined headers (see mkSend
-- for details)
-- - Body: The payload
--
mkMessage :: String -> String -> String -> String -> Type -> Int -> [Header] -> Body -> Frame
-- | make a Receipt frame (Broker -> Application). The parameters
-- are:
--
--
-- - Error Message Id: A short error description
-- - Receipt Id: The receipt of frame sent by the application to which
-- this error relates
-- - Type: The format of the error message as MIME Type
-- - Length: The length of the error message
-- - Header: List of additional, broker-specific headers
-- - Body: The error message
--
mkErr :: String -> String -> Type -> Int -> [Header] -> Body -> Frame
-- | make a Begin frame (Application -> Broker). The parameters
-- are:
--
--
-- - Transaction: A unique transaction identifier defined by the
-- application.
-- - Receipt: A receipt (see mkSubscribe for details)
-- - Header: Additional, broker-specific headers
--
mkBegin :: String -> String -> [Header] -> Frame
-- | make a Commit frame (Application -> Broker). The parameters
-- are:
--
--
-- - Transaction: A unique transaction identifier defined by
-- the application.
-- - Receipt: A receipt (see mkSubscribe for
-- details)
-- - Header: Additional, broker-specific headers
--
mkCommit :: String -> String -> [Header] -> Frame
-- | make an Abort frame (Application -> Broker). The parameters
-- are:
--
--
-- - Transaction: A unique transaction identifier defined by the
-- application.
-- - Receipt: A receipt (see mkSubscribe for details)
-- - Header: Additional, broker-specific headers
--
mkAbort :: String -> String -> [Header] -> Frame
-- | make an Ack frame (Application -> Broker). The parameters
-- are:
--
--
-- - Message Id: The identifier of the message to be ack'd
-- - Subscription Id: The subscription, through which the message was
-- received
-- - Transaction: Acks may be part of a transaction (see mkSend
-- for details).
-- - Receipt: see mkSubscribe for details
--
mkAck :: String -> String -> String -> String -> [Header] -> Frame
-- | make a Nack frame (Application -> Broker). The parameters
-- are:
--
--
-- - Message Id: The identifier of the message to be nack'd
-- - Subscription Id: The subscription, through which the message was
-- received
-- - Transaction: Nacks may be part of a transaction (see mkSend
-- for details).
-- - Receipt: see mkSubscribe for details
--
mkNack :: String -> String -> String -> String -> [Header] -> Frame
-- | make a Disconnect frame (Application -> Broker). The
-- parameter is:
--
--
mkDisconnect :: String -> [Header] -> Frame
-- | make a HeatBeat frame (Application -> Broker and Broker
-- -> Application)
mkBeat :: Frame
-- | make a Receipt frame (Broker -> Application). The parameter
-- is:
--
--
-- - Receipt: The receipt identifier received from the application
-- - Header: List of additional, broker-specific headers
--
mkReceipt :: String -> [Header] -> Frame
-- | make Connect frame
mkConFrame :: [Header] -> Either String Frame
-- | make Stomp frame
mkStmpFrame :: [Header] -> Either String Frame
-- | make Connected frame
mkCondFrame :: [Header] -> Either String Frame
-- | make Disconnect frame
mkDisFrame :: [Header] -> Either String Frame
-- | make Subscribe frame
mkSubFrame :: [Header] -> Either String Frame
-- | make Unsubscribe frame
mkUSubFrame :: [Header] -> Either String Frame
-- | make Send frame
mkSndFrame :: [Header] -> Int -> Body -> Either String Frame
-- | make Message frame
mkMsgFrame :: [Header] -> Int -> Body -> Either String Frame
-- | make Error frame
mkErrFrame :: [Header] -> Int -> Body -> Either String Frame
-- | make Begin frame
mkBgnFrame :: [Header] -> Either String Frame
-- | make Commit frame
mkCmtFrame :: [Header] -> Either String Frame
-- | make Abort frame
mkAbrtFrame :: [Header] -> Either String Frame
-- | make Ack frame
mkAckFrame :: [Header] -> Either String Frame
-- | make Nack frame
mkNackFrame :: [Header] -> Either String Frame
-- | make Receipt frame
mkRecFrame :: [Header] -> Either String Frame
-- | make login header
mkLogHdr :: String -> Header
-- | make passcode header
mkPassHdr :: String -> Header
-- | make destination header
mkDestHdr :: String -> Header
-- | make content-length header
mkLenHdr :: String -> Header
-- | make transaction header
mkTrnHdr :: String -> Header
-- | make receipt header
mkRecHdr :: String -> Header
-- | make selector header
mkSelHdr :: String -> Header
-- | make id header (subscribe frame)
mkIdHdr :: String -> Header
-- | make ack header (subscribe frame)
mkAckHdr :: String -> Header
-- | make session header (connected frame)
mkSesHdr :: String -> Header
-- | make message header (error frame)
mkMsgHdr :: String -> Header
-- | make message-id header
mkMIdHdr :: String -> Header
-- | make accept-version header (connect frame)
mkAcVerHdr :: String -> Header
-- | make version header (connected frame)
mkVerHdr :: String -> Header
-- | make host header (connect frame)
mkHostHdr :: String -> Header
-- | make heart-beat header
mkBeatHdr :: String -> Header
-- | make content-type header
mkMimeHdr :: String -> Header
-- | make server header (connected frame)
mkSrvHdr :: String -> Header
-- | make subscription header
mkSubHdr :: String -> Header
-- | make client-id header
mkCliIdHdr :: String -> Header
-- | convert String to Version
valToVer :: String -> Maybe Version
-- | convert String to list of Version
valToVers :: String -> Maybe [Version]
-- | convert Version to String
verToVal :: Version -> String
-- | convert list of Version to String
versToVal :: [Version] -> String
-- | convert HeartBeat to String
beatToVal :: Heart -> String
-- | convert String to HeartBeat
valToBeat :: String -> Maybe Heart
-- | convert AckMode to String
ackToVal :: AckMode -> String
-- | convert String to AckMode
valToAck :: String -> Maybe AckMode
-- | convert String to SrvDesc
strToSrv :: String -> SrvDesc
-- | convert SrvDesc to String
srvToStr :: SrvDesc -> String
-- | negotiates version - if no common version is found, the function
-- results in version 1.0!
negoVersion :: [Version] -> [Version] -> Version
-- | negotiates heart-beat
negoBeat :: Heart -> Heart -> Heart
-- | remove header (String) from list of Header
rmHdr :: [Header] -> String -> [Header]
-- | remove headers (list of String) from list of Header
rmHdrs :: [Header] -> [String] -> [Header]
getAck :: [Header] -> Either String AckMode
getLen :: [Header] -> Either String Int
-- | gets the FrameType of a Frame
typeOf :: Frame -> FrameType
-- | converts a Frame into a ByteString
putFrame :: Frame -> ByteString
-- | converts a Frame into a String
toString :: Frame -> String
-- | converts the FrameType into a ByteString
putCommand :: Frame -> ByteString
-- | converts a Send frame into a Message frame; parameters:
--
--
-- - message id
-- - subscription id
-- - The original Send frame
--
sndToMsg :: String -> String -> String -> Frame -> Maybe Frame
-- | converts a Connect frame into a Connected frame,
-- negotiating heart-beats and version; parameters:
--
--
-- - server desc
-- - session id
-- - caller's bid for heart-beat
-- - caller's supported versions
-- - the original Connect frame
--
conToCond :: String -> String -> Heart -> [Version] -> Frame -> Maybe Frame
-- | sets the transaction header to an empty string; this is a useful
-- function for brokers: when a transaction has been committed, the
-- Send messages can be handled by the same function without,
-- accidentally, iterating into a new transaction.
resetTrans :: Frame -> Frame
-- | Compliance with protocol version
complies :: Version -> Frame -> Bool
-- | get destination from Subscribe, Unsubscribe,
-- Send or Message
getDest :: Frame -> String
-- | get transaction from Send, Ack, Nack,
-- Begin, Commit or Abort
getTrans :: Frame -> String
-- | get receipt or receipt-id from any frame, but
-- Connect, Connected, Message, Error
getReceipt :: Frame -> String
-- | get login from Connect
getLogin :: Frame -> String
-- | get passcode from Connect
getPasscode :: Frame -> String
-- | get client-id from Connect
getCliId :: Frame -> String
-- | get host from Connect
getHost :: Frame -> String
-- | get accept-version from Connect
getVersions :: Frame -> [Version]
-- | get version from Connected
getVersion :: Frame -> Version
-- | get heart-beat from Connect or Connected
getBeat :: Frame -> Heart
-- | get session from Connected
getSession :: Frame -> String
-- | get server from Connected
getServer :: Frame -> SrvDesc
-- | get subscription from Ack, Nack or Message
getSub :: Frame -> String
-- | get selector from Subscribe
getSelector :: Frame -> String
-- | get id from Subscribe or Unsubscribe
getId :: Frame -> String
-- | get ack from Subscribe
getAcknow :: Frame -> AckMode
-- | get ack or message-id from Message
getMsgAck :: Frame -> String
-- | get body from Send, Message, Error
getBody :: Frame -> ByteString
-- | get content-type from Send, Message, Error
getMime :: Frame -> Type
-- | get content-length from Send, Message,
-- Error
getLength :: Frame -> Int
-- | get message from Error
getMsg :: Frame -> String
-- | get all additional headers from Send or Message
getHeaders :: Frame -> [Header]
-- | snoc
(|>) :: ByteString -> Word8 -> ByteString
infixr 9 |>
-- | cons
(<|) :: Word8 -> ByteString -> ByteString
infixr 9 <|
-- | append
(>|<) :: ByteString -> ByteString -> ByteString
infixr 9 >|<
upString :: String -> String
numeric :: String -> Bool
instance GHC.Classes.Eq Network.Mom.Stompl.Frame.Frame
instance GHC.Show.Show Network.Mom.Stompl.Frame.Frame
instance GHC.Classes.Eq Network.Mom.Stompl.Frame.AckMode
instance GHC.Classes.Eq Network.Mom.Stompl.Frame.FrameType
instance GHC.Read.Read Network.Mom.Stompl.Frame.FrameType
instance GHC.Show.Show Network.Mom.Stompl.Frame.FrameType
instance GHC.Show.Show Network.Mom.Stompl.Frame.AckMode
instance GHC.Read.Read Network.Mom.Stompl.Frame.AckMode
-- | Stomp Parser based on Attoparsec
module Network.Mom.Stompl.Parser
-- | The Stomp Parser
stompParser :: Parser Frame
-- | Parses a ByteString at once with Attoparsec parseOnly. May fail
-- or conclude.
stompAtOnce :: ByteString -> Either String Frame