-- ------------------------------------------------------------ -- -- protocol handler functions -- configuration file -- real handler is generated with cpp -- -- Version : $Id: ProtocolHandler.Config.hs,v 1.2 2004/03/19 19:09:39 hxml Exp $ module ProtocolHandler ( getProtocolHandler ) where import XmlState -- ------------------------------------------------------------ -- -- file io and network import Data.Maybe ( fromMaybe ) import Network.URI ( URI , scheme ) import ProtocolHandlerFile ( getFileContents ) #ifdef ONLY_NATIVE_HTTP import ProtocolHandlerHttpNative ( getHttpContentsWithHttp ) #else #ifdef ONLY_CURL_HTTP import ProtocolHandlerHttpCurl ( getHttpContentsWithCurl ) #else #ifdef NO_HTTP #else import ProtocolHandlerHttpNativeOrCurl ( getHttpContentsNativeOrWithCurl ) #endif #endif #endif -- ------------------------------------------------------------ -- getProtocolHandler :: String -> (URI -> XmlStateFilter a) getProtocolHandler proto = fromMaybe getUnsupported handler where handler = lookup proto protocolHandler -- -- the fall back protocol handler getUnsupported :: URI -> XmlStateFilter a getUnsupported uri = addFatal ( "unsupported protocol " ++ show (scheme uri) ++ " in URI: " ++ show uri ) -- ------------------------------------------------------------ -- -- the table of potocol handlers -- looked up in getProtocolHandler protocolHandler :: [(String, URI -> XmlStateFilter a)] protocolHandler = [ ("file", getFileContents) , ("http", #ifdef ONLY_NATIVE_HTTP getHttpContentsWithHttp #else #ifdef ONLY_CURL_HTTP getHttpContentsWithCurl #else #ifdef NO_HTTP getUnsupported #else getHttpContentsNativeOrWithCurl #endif #endif #endif ) ] -- ------------------------------------------------------------