haxr-3000.11.1.2: XML-RPC client and server library.

Copyright | (c) Bjorn Bringert 2003
License | BSD-style
Maintainer | bjorn@bringert.net
Stability | experimental
Portability | non-portable (requires extensions and non-portable libraries)
Safe Haskell | None
Language | Haskell2010

Network.XmlRpc.Internals

Contents

- Method calls and repsonses
- XML-RPC types
- Converting from XML
- Converting to XML
- Converting to and from DTD types
- Error monad

Description

This module contains the core functionality of the XML-RPC library. Most applications should not need to use this module. Client applications should use Network.XmlRpc.Client and server applications should use Network.XmlRpc.Server.

The XML-RPC specifcation is available at http://www.xmlrpc.com/spec.

Synopsis

- data MethodCall = MethodCall String [Value]
- data MethodResponse
  - = Return Value
  - | Fault Int String
- data Value
  - = ValueInt Int
  - | ValueBool Bool
  - | ValueString String
  - | ValueUnwrapped String
  - | ValueDouble Double
  - | ValueDateTime LocalTime
  - | ValueBase64 ByteString
  - | ValueStruct [(String, Value)]
  - | ValueArray [Value]
- data Type
  - = TInt
  - | TBool
  - | TString
  - | TDouble
  - | TDateTime
  - | TBase64
  - | TStruct
  - | TArray
  - | TUnknown
- class XmlRpcType a where
  - toValue :: a -> Value
  - fromValue :: Monad m => Value -> Err m a
  - getType :: a -> Type
- parseResponse :: (Show e, MonadError e m) => String -> Err m MethodResponse
- parseCall :: (Show e, MonadError e m) => String -> Err m MethodCall
- getField :: (Monad m, XmlRpcType a) => String -> [(String, Value)] -> Err m a
- getFieldMaybe :: (Monad m, XmlRpcType a) => String -> [(String, Value)] -> Err m (Maybe a)
- renderCall :: MethodCall -> ByteString
- renderResponse :: MethodResponse -> ByteString
- toXRValue :: Value -> Value
- fromXRValue :: Monad m => Value -> Err m Value
- toXRMethodCall :: MethodCall -> MethodCall
- fromXRMethodCall :: Monad m => MethodCall -> Err m MethodCall
- toXRMethodResponse :: MethodResponse -> MethodResponse
- fromXRMethodResponse :: Monad m => MethodResponse -> Err m MethodResponse
- toXRParams :: [Value] -> Params
- fromXRParams :: Monad m => Params -> Err m [Value]
- toXRMember :: (String, Value) -> Member
- fromXRMember :: Monad m => Member -> Err m (String, Value)
- type Err m a = ExceptT String m a
- maybeToM :: Monad m => String -> Maybe a -> m a
- handleError :: Monad m => (String -> m a) -> Err m a -> m a
- ioErrorToErr :: IO a -> Err IO a

# Method calls and repsonses

data MethodCall Source

An XML-RPC method call. Consists of a method name and a list of parameters.

Constructors

MethodCall String [Value] |

Instances

Eq MethodCall Source |
Show MethodCall Source |

data MethodResponse Source

An XML-RPC response.

Constructors

Return Value | A method response returning a value
Fault Int String | A fault response

Instances

Eq MethodResponse Source |
Show MethodResponse Source |

# XML-RPC types

data Value Source

An XML-RPC value.

Constructors

ValueInt Int | int, i4, or i8
ValueBool Bool | bool
ValueString String | string
ValueUnwrapped String | no inner element
ValueDouble Double | double
ValueDateTime LocalTime | dateTime.iso8601
ValueBase64 ByteString | base 64. NOTE that you should provide the raw data; the haxr library takes care of doing the base-64 encoding.
ValueStruct [(String, Value)] | struct
ValueArray [Value] | array

Instances

Eq Value Source |
Show Value Source |
XmlRpcType Value Source | Exists to allow explicit type conversions.

data Type Source

An XML-RPC value. Use for error messages and introspection.

Constructors

TInt |
TBool |
TString |
TDouble |
TDateTime |
TBase64 |
TStruct |
TArray |
TUnknown |

Instances

Eq Type Source |
Read Type Source |
Show Type Source |

class XmlRpcType a where Source

A class for mapping Haskell types to XML-RPC types.

Methods

toValue :: a -> Value Source

Convert from this type to a `Value`

fromValue :: Monad m => Value -> Err m a Source

Convert from a `Value` to this type. May fail if if there is a type error.

getType :: a -> Type Source

Instances

XmlRpcType Bool Source |
XmlRpcType Double Source |
XmlRpcType Int Source |
XmlRpcType String Source |
XmlRpcType ByteString Source |
XmlRpcType CalendarTime Source |
XmlRpcType LocalTime Source |
XmlRpcType Value Source | Exists to allow explicit type conversions.
XmlRpcType a => XmlRpcType [(String, a)] Source |
XmlRpcType a => XmlRpcType [a] Source |
(XmlRpcType a, XmlRpcType b) => XmlRpcType (a, b) Source |
(XmlRpcType a, XmlRpcType b, XmlRpcType c) => XmlRpcType (a, b, c) Source |
(XmlRpcType a, XmlRpcType b, XmlRpcType c, XmlRpcType d) => XmlRpcType (a, b, c, d) Source |
(XmlRpcType a, XmlRpcType b, XmlRpcType c, XmlRpcType d, XmlRpcType e) => XmlRpcType (a, b, c, d, e) Source |

# Converting from XML

parseResponse :: (Show e, MonadError e m) => String -> Err m MethodResponse Source

Parses a method response from XML.

parseCall :: (Show e, MonadError e m) => String -> Err m MethodCall Source

Parses a method call from XML.

getField Source

Arguments

:: (Monad m, XmlRpcType a) |
=> String | Field name
-> [(String, Value)] | Struct
-> Err m a |

Get a field value from a (possibly heterogeneous) struct.

getFieldMaybe Source

Arguments

:: (Monad m, XmlRpcType a) |
=> String | Field name
-> [(String, Value)] | Struct
-> Err m (Maybe a) |

Get a field value from a (possibly heterogeneous) struct.

# Converting to XML

renderCall :: MethodCall -> ByteString Source

Makes an XML-representation of a method call. FIXME: pretty prints ugly XML

renderResponse :: MethodResponse -> ByteString Source

Makes an XML-representation of a method response. FIXME: pretty prints ugly XML

# Converting to and from DTD types

toXRValue :: Value -> Value Source

fromXRValue :: Monad m => Value -> Err m Value Source

toXRMethodCall :: MethodCall -> MethodCall Source

fromXRMethodCall :: Monad m => MethodCall -> Err m MethodCall Source

toXRMethodResponse :: MethodResponse -> MethodResponse Source

fromXRMethodResponse :: Monad m => MethodResponse -> Err m MethodResponse Source

toXRParams :: [Value] -> Params Source

fromXRParams :: Monad m => Params -> Err m [Value] Source

toXRMember :: (String, Value) -> Member Source

fromXRMember :: Monad m => Member -> Err m (String, Value) Source

# Error monad

type Err m a = ExceptT String m a Source

maybeToM Source

Arguments

:: Monad m |
=> String | Error message to fail with for `Nothing`
-> Maybe a | The `Maybe` value.
-> m a | The resulting value in the monad.

Convert a `Maybe` value to a value in any monad

handleError :: Monad m => (String -> m a) -> Err m a -> m a Source

Handle errors from the error monad.

ioErrorToErr :: IO a -> Err IO a Source

Catch IO errors in the error monad.