diff --git a/System/LibVirt/Errors.hs b/System/LibVirt/Errors.hs
new file mode 100644
--- /dev/null
+++ b/System/LibVirt/Errors.hs
@@ -0,0 +1,565 @@
+-- GENERATED by C->Haskell Compiler, version 0.16.3 Crystal Seed, 24 Jan 2009 (Haskell)
+-- Edit the ORIGNAL .chs file instead!
+
+
+{-# LINE 1 "System/LibVirt/Errors.chs" #-}{-# LANGUAGE ForeignFunctionInterface, ScopedTypeVariables, StandaloneDeriving, DeriveDataTypeable #-}
+
+
+{-# LINE 3 "System/LibVirt/Errors.chs" #-}
+
+
+module System.LibVirt.Errors
+  (Error (..), ErrorLevel (..),
+   ErrorDomain (..), ErrorNumber (..),
+   catchVirtError,
+   exceptionOnMinusOne,
+   ptrToConnection, ptrToDomain, ptrToNetwork,
+   connectionToPtr, domainToPtr, networkToPtr)
+  where
+
+import qualified Control.Exception as E
+import Data.Generics
+import Foreign
+import Foreign.C.Types
+import Foreign.C.String
+
+import System.LibVirt.Internal
+{-# LINE 22 "System/LibVirt/Errors.chs" #-}
+
+data ErrorLevel = ErrNone
+                | ErrWarning
+                | ErrError
+                deriving (Eq,Show)
+instance Enum ErrorLevel where
+  fromEnum ErrNone = 0
+  fromEnum ErrWarning = 1
+  fromEnum ErrError = 2
+
+  toEnum 0 = ErrNone
+  toEnum 1 = ErrWarning
+  toEnum 2 = ErrError
+  toEnum unmatched = error ("ErrorLevel.toEnum: Cannot match " ++ show unmatched)
+
+{-# LINE 24 "System/LibVirt/Errors.chs" #-}
+deriving instance Data ErrorLevel
+deriving instance Typeable ErrorLevel
+
+data ErrorDomain = FromNone
+                 | FromXen
+                 | FromXend
+                 | FromXenstore
+                 | FromSexpr
+                 | FromXml
+                 | FromDom
+                 | FromRpc
+                 | FromProxy
+                 | FromConf
+                 | FromQemu
+                 | FromNet
+                 | FromTest
+                 | FromRemote
+                 | FromOpenvz
+                 | FromXenxm
+                 | FromStatsLinux
+                 | FromLxc
+                 | FromStorage
+                 | FromNetwork
+                 | FromDomain
+                 | FromUml
+                 | FromNodedev
+                 | FromXenInotify
+                 | FromSecurity
+                 | FromVbox
+                 | FromInterface
+                 | FromOne
+                 | FromEsx
+                 | FromPhyp
+                 | FromSecret
+                 | FromCpu
+                 | FromXenapi
+                 | FromNwfilter
+                 | FromHook
+                 | FromDomainSnapshot
+                 | FromAudit
+                 | FromSysinfo
+                 | FromStreams
+                 | FromVmware
+                 | FromEvent
+                 | FromLibxl
+                 | FromLocking
+                 | FromHyperv
+                 | FromCapabilities
+                 deriving (Eq,Show)
+instance Enum ErrorDomain where
+  fromEnum FromNone = 0
+  fromEnum FromXen = 1
+  fromEnum FromXend = 2
+  fromEnum FromXenstore = 3
+  fromEnum FromSexpr = 4
+  fromEnum FromXml = 5
+  fromEnum FromDom = 6
+  fromEnum FromRpc = 7
+  fromEnum FromProxy = 8
+  fromEnum FromConf = 9
+  fromEnum FromQemu = 10
+  fromEnum FromNet = 11
+  fromEnum FromTest = 12
+  fromEnum FromRemote = 13
+  fromEnum FromOpenvz = 14
+  fromEnum FromXenxm = 15
+  fromEnum FromStatsLinux = 16
+  fromEnum FromLxc = 17
+  fromEnum FromStorage = 18
+  fromEnum FromNetwork = 19
+  fromEnum FromDomain = 20
+  fromEnum FromUml = 21
+  fromEnum FromNodedev = 22
+  fromEnum FromXenInotify = 23
+  fromEnum FromSecurity = 24
+  fromEnum FromVbox = 25
+  fromEnum FromInterface = 26
+  fromEnum FromOne = 27
+  fromEnum FromEsx = 28
+  fromEnum FromPhyp = 29
+  fromEnum FromSecret = 30
+  fromEnum FromCpu = 31
+  fromEnum FromXenapi = 32
+  fromEnum FromNwfilter = 33
+  fromEnum FromHook = 34
+  fromEnum FromDomainSnapshot = 35
+  fromEnum FromAudit = 36
+  fromEnum FromSysinfo = 37
+  fromEnum FromStreams = 38
+  fromEnum FromVmware = 39
+  fromEnum FromEvent = 40
+  fromEnum FromLibxl = 41
+  fromEnum FromLocking = 42
+  fromEnum FromHyperv = 43
+  fromEnum FromCapabilities = 44
+
+  toEnum 0 = FromNone
+  toEnum 1 = FromXen
+  toEnum 2 = FromXend
+  toEnum 3 = FromXenstore
+  toEnum 4 = FromSexpr
+  toEnum 5 = FromXml
+  toEnum 6 = FromDom
+  toEnum 7 = FromRpc
+  toEnum 8 = FromProxy
+  toEnum 9 = FromConf
+  toEnum 10 = FromQemu
+  toEnum 11 = FromNet
+  toEnum 12 = FromTest
+  toEnum 13 = FromRemote
+  toEnum 14 = FromOpenvz
+  toEnum 15 = FromXenxm
+  toEnum 16 = FromStatsLinux
+  toEnum 17 = FromLxc
+  toEnum 18 = FromStorage
+  toEnum 19 = FromNetwork
+  toEnum 20 = FromDomain
+  toEnum 21 = FromUml
+  toEnum 22 = FromNodedev
+  toEnum 23 = FromXenInotify
+  toEnum 24 = FromSecurity
+  toEnum 25 = FromVbox
+  toEnum 26 = FromInterface
+  toEnum 27 = FromOne
+  toEnum 28 = FromEsx
+  toEnum 29 = FromPhyp
+  toEnum 30 = FromSecret
+  toEnum 31 = FromCpu
+  toEnum 32 = FromXenapi
+  toEnum 33 = FromNwfilter
+  toEnum 34 = FromHook
+  toEnum 35 = FromDomainSnapshot
+  toEnum 36 = FromAudit
+  toEnum 37 = FromSysinfo
+  toEnum 38 = FromStreams
+  toEnum 39 = FromVmware
+  toEnum 40 = FromEvent
+  toEnum 41 = FromLibxl
+  toEnum 42 = FromLocking
+  toEnum 43 = FromHyperv
+  toEnum 44 = FromCapabilities
+  toEnum unmatched = error ("ErrorDomain.toEnum: Cannot match " ++ show unmatched)
+
+{-# LINE 28 "System/LibVirt/Errors.chs" #-}
+deriving instance Data ErrorDomain
+deriving instance Typeable ErrorDomain
+
+data Error = Error {
+  veCode :: ErrorNumber,
+  veDomain :: ErrorDomain,
+  veMessage :: String,
+  veLevel :: ErrorLevel,
+  veConnect :: Connection,
+  veDom :: Domain,
+  veStr1 :: Maybe String,
+  veStr2 :: Maybe String,
+  veStr3 :: Maybe String,
+  veInt1 :: Int,
+  veInt2 :: Int,
+  veNet :: Network }
+  deriving (Eq, Show, Data, Typeable)
+
+instance E.Exception Error
+
+type VirtErrorPtr = Ptr (Error)
+{-# LINE 49 "System/LibVirt/Errors.chs" #-}
+
+data ErrorNumber = ErrOk
+                 | ErrInternalError
+                 | ErrNoMemory
+                 | ErrNoSupport
+                 | ErrUnknownHost
+                 | ErrNoConnect
+                 | ErrInvalidConn
+                 | ErrInvalidDomain
+                 | ErrInvalidArg
+                 | ErrOperationFailed
+                 | ErrGetFailed
+                 | ErrPostFailed
+                 | ErrHttpError
+                 | ErrSexprSerial
+                 | ErrNoXen
+                 | ErrXenCall
+                 | ErrOsType
+                 | ErrNoKernel
+                 | ErrNoRoot
+                 | ErrNoSource
+                 | ErrNoTarget
+                 | ErrNoName
+                 | ErrNoOs
+                 | ErrNoDevice
+                 | ErrNoXenstore
+                 | ErrDriverFull
+                 | ErrCallFailed
+                 | ErrXmlError
+                 | ErrDomExist
+                 | ErrOperationDenied
+                 | ErrOpenFailed
+                 | ErrReadFailed
+                 | ErrParseFailed
+                 | ErrConfSyntax
+                 | ErrWriteFailed
+                 | ErrXmlDetail
+                 | ErrInvalidNetwork
+                 | ErrNetworkExist
+                 | ErrSystemError
+                 | ErrRpc
+                 | ErrGnutlsError
+                 | WarNoNetwork
+                 | ErrNoDomain
+                 | ErrNoNetwork
+                 | ErrInvalidMac
+                 | ErrAuthFailed
+                 | ErrInvalidStoragePool
+                 | ErrInvalidStorageVol
+                 | WarNoStorage
+                 | ErrNoStoragePool
+                 | ErrNoStorageVol
+                 | WarNoNode
+                 | ErrInvalidNodeDevice
+                 | ErrNoNodeDevice
+                 | ErrNoSecurityModel
+                 | ErrOperationInvalid
+                 | WarNoInterface
+                 | ErrNoInterface
+                 | ErrInvalidInterface
+                 | ErrMultipleInterfaces
+                 | WarNoNwfilter
+                 | ErrInvalidNwfilter
+                 | ErrNoNwfilter
+                 | ErrBuildFirewall
+                 | WarNoSecret
+                 | ErrInvalidSecret
+                 | ErrNoSecret
+                 | ErrConfigUnsupported
+                 | ErrOperationTimeout
+                 | ErrMigratePersistFailed
+                 | ErrHookScriptFailed
+                 | ErrInvalidDomainSnapshot
+                 | ErrNoDomainSnapshot
+                 | ErrInvalidStream
+                 | ErrArgumentUnsupported
+                 | ErrStorageProbeFailed
+                 | ErrStoragePoolBuilt
+                 | ErrSnapshotRevertRisky
+                 | ErrOperationAborted
+                 deriving (Eq,Show)
+instance Enum ErrorNumber where
+  fromEnum ErrOk = 0
+  fromEnum ErrInternalError = 1
+  fromEnum ErrNoMemory = 2
+  fromEnum ErrNoSupport = 3
+  fromEnum ErrUnknownHost = 4
+  fromEnum ErrNoConnect = 5
+  fromEnum ErrInvalidConn = 6
+  fromEnum ErrInvalidDomain = 7
+  fromEnum ErrInvalidArg = 8
+  fromEnum ErrOperationFailed = 9
+  fromEnum ErrGetFailed = 10
+  fromEnum ErrPostFailed = 11
+  fromEnum ErrHttpError = 12
+  fromEnum ErrSexprSerial = 13
+  fromEnum ErrNoXen = 14
+  fromEnum ErrXenCall = 15
+  fromEnum ErrOsType = 16
+  fromEnum ErrNoKernel = 17
+  fromEnum ErrNoRoot = 18
+  fromEnum ErrNoSource = 19
+  fromEnum ErrNoTarget = 20
+  fromEnum ErrNoName = 21
+  fromEnum ErrNoOs = 22
+  fromEnum ErrNoDevice = 23
+  fromEnum ErrNoXenstore = 24
+  fromEnum ErrDriverFull = 25
+  fromEnum ErrCallFailed = 26
+  fromEnum ErrXmlError = 27
+  fromEnum ErrDomExist = 28
+  fromEnum ErrOperationDenied = 29
+  fromEnum ErrOpenFailed = 30
+  fromEnum ErrReadFailed = 31
+  fromEnum ErrParseFailed = 32
+  fromEnum ErrConfSyntax = 33
+  fromEnum ErrWriteFailed = 34
+  fromEnum ErrXmlDetail = 35
+  fromEnum ErrInvalidNetwork = 36
+  fromEnum ErrNetworkExist = 37
+  fromEnum ErrSystemError = 38
+  fromEnum ErrRpc = 39
+  fromEnum ErrGnutlsError = 40
+  fromEnum WarNoNetwork = 41
+  fromEnum ErrNoDomain = 42
+  fromEnum ErrNoNetwork = 43
+  fromEnum ErrInvalidMac = 44
+  fromEnum ErrAuthFailed = 45
+  fromEnum ErrInvalidStoragePool = 46
+  fromEnum ErrInvalidStorageVol = 47
+  fromEnum WarNoStorage = 48
+  fromEnum ErrNoStoragePool = 49
+  fromEnum ErrNoStorageVol = 50
+  fromEnum WarNoNode = 51
+  fromEnum ErrInvalidNodeDevice = 52
+  fromEnum ErrNoNodeDevice = 53
+  fromEnum ErrNoSecurityModel = 54
+  fromEnum ErrOperationInvalid = 55
+  fromEnum WarNoInterface = 56
+  fromEnum ErrNoInterface = 57
+  fromEnum ErrInvalidInterface = 58
+  fromEnum ErrMultipleInterfaces = 59
+  fromEnum WarNoNwfilter = 60
+  fromEnum ErrInvalidNwfilter = 61
+  fromEnum ErrNoNwfilter = 62
+  fromEnum ErrBuildFirewall = 63
+  fromEnum WarNoSecret = 64
+  fromEnum ErrInvalidSecret = 65
+  fromEnum ErrNoSecret = 66
+  fromEnum ErrConfigUnsupported = 67
+  fromEnum ErrOperationTimeout = 68
+  fromEnum ErrMigratePersistFailed = 69
+  fromEnum ErrHookScriptFailed = 70
+  fromEnum ErrInvalidDomainSnapshot = 71
+  fromEnum ErrNoDomainSnapshot = 72
+  fromEnum ErrInvalidStream = 73
+  fromEnum ErrArgumentUnsupported = 74
+  fromEnum ErrStorageProbeFailed = 75
+  fromEnum ErrStoragePoolBuilt = 76
+  fromEnum ErrSnapshotRevertRisky = 77
+  fromEnum ErrOperationAborted = 78
+
+  toEnum 0 = ErrOk
+  toEnum 1 = ErrInternalError
+  toEnum 2 = ErrNoMemory
+  toEnum 3 = ErrNoSupport
+  toEnum 4 = ErrUnknownHost
+  toEnum 5 = ErrNoConnect
+  toEnum 6 = ErrInvalidConn
+  toEnum 7 = ErrInvalidDomain
+  toEnum 8 = ErrInvalidArg
+  toEnum 9 = ErrOperationFailed
+  toEnum 10 = ErrGetFailed
+  toEnum 11 = ErrPostFailed
+  toEnum 12 = ErrHttpError
+  toEnum 13 = ErrSexprSerial
+  toEnum 14 = ErrNoXen
+  toEnum 15 = ErrXenCall
+  toEnum 16 = ErrOsType
+  toEnum 17 = ErrNoKernel
+  toEnum 18 = ErrNoRoot
+  toEnum 19 = ErrNoSource
+  toEnum 20 = ErrNoTarget
+  toEnum 21 = ErrNoName
+  toEnum 22 = ErrNoOs
+  toEnum 23 = ErrNoDevice
+  toEnum 24 = ErrNoXenstore
+  toEnum 25 = ErrDriverFull
+  toEnum 26 = ErrCallFailed
+  toEnum 27 = ErrXmlError
+  toEnum 28 = ErrDomExist
+  toEnum 29 = ErrOperationDenied
+  toEnum 30 = ErrOpenFailed
+  toEnum 31 = ErrReadFailed
+  toEnum 32 = ErrParseFailed
+  toEnum 33 = ErrConfSyntax
+  toEnum 34 = ErrWriteFailed
+  toEnum 35 = ErrXmlDetail
+  toEnum 36 = ErrInvalidNetwork
+  toEnum 37 = ErrNetworkExist
+  toEnum 38 = ErrSystemError
+  toEnum 39 = ErrRpc
+  toEnum 40 = ErrGnutlsError
+  toEnum 41 = WarNoNetwork
+  toEnum 42 = ErrNoDomain
+  toEnum 43 = ErrNoNetwork
+  toEnum 44 = ErrInvalidMac
+  toEnum 45 = ErrAuthFailed
+  toEnum 46 = ErrInvalidStoragePool
+  toEnum 47 = ErrInvalidStorageVol
+  toEnum 48 = WarNoStorage
+  toEnum 49 = ErrNoStoragePool
+  toEnum 50 = ErrNoStorageVol
+  toEnum 51 = WarNoNode
+  toEnum 52 = ErrInvalidNodeDevice
+  toEnum 53 = ErrNoNodeDevice
+  toEnum 54 = ErrNoSecurityModel
+  toEnum 55 = ErrOperationInvalid
+  toEnum 56 = WarNoInterface
+  toEnum 57 = ErrNoInterface
+  toEnum 58 = ErrInvalidInterface
+  toEnum 59 = ErrMultipleInterfaces
+  toEnum 60 = WarNoNwfilter
+  toEnum 61 = ErrInvalidNwfilter
+  toEnum 62 = ErrNoNwfilter
+  toEnum 63 = ErrBuildFirewall
+  toEnum 64 = WarNoSecret
+  toEnum 65 = ErrInvalidSecret
+  toEnum 66 = ErrNoSecret
+  toEnum 67 = ErrConfigUnsupported
+  toEnum 68 = ErrOperationTimeout
+  toEnum 69 = ErrMigratePersistFailed
+  toEnum 70 = ErrHookScriptFailed
+  toEnum 71 = ErrInvalidDomainSnapshot
+  toEnum 72 = ErrNoDomainSnapshot
+  toEnum 73 = ErrInvalidStream
+  toEnum 74 = ErrArgumentUnsupported
+  toEnum 75 = ErrStorageProbeFailed
+  toEnum 76 = ErrStoragePoolBuilt
+  toEnum 77 = ErrSnapshotRevertRisky
+  toEnum 78 = ErrOperationAborted
+  toEnum unmatched = error ("ErrorNumber.toEnum: Cannot match " ++ show unmatched)
+
+{-# LINE 51 "System/LibVirt/Errors.chs" #-}
+
+deriving instance Data ErrorNumber
+deriving instance Typeable ErrorNumber
+
+data UnknownError = UnknownError
+  deriving (Eq, Show, Data, Typeable)
+
+instance E.Exception UnknownError
+
+peekCString' :: CString -> IO (Maybe String)
+peekCString' ptr
+  | ptr == nullPtr = return Nothing
+  | otherwise = Just `fmap` peekCString ptr
+
+convertError :: Ptr () -> IO (Maybe Error)
+convertError ptr
+  | ptr == nullPtr = return Nothing
+  | otherwise = do
+  let err = castPtr ptr :: VirtErrorPtr
+  code <- (\ptr -> do {peekByteOff ptr 0 ::IO CInt}) err
+  domain <- (\ptr -> do {peekByteOff ptr 4 ::IO CInt}) err
+  message <- peekCString =<< (\ptr -> do {peekByteOff ptr 8 ::IO (Ptr CChar)}) err
+  level <- (\ptr -> do {peekByteOff ptr 16 ::IO CInt}) err
+  conn <- ptrToConnection' =<< (\ptr -> do {peekByteOff ptr 24 ::IO (Ptr ())}) err
+  dom  <- ptrToDomain' =<< (\ptr -> do {peekByteOff ptr 32 ::IO (Ptr ())}) err
+  str1 <- peekCString' =<< (\ptr -> do {peekByteOff ptr 40 ::IO (Ptr CChar)}) err
+  str2 <- peekCString' =<< (\ptr -> do {peekByteOff ptr 48 ::IO (Ptr CChar)}) err
+  str3 <- peekCString' =<< (\ptr -> do {peekByteOff ptr 56 ::IO (Ptr CChar)}) err
+  int1 <- (\ptr -> do {peekByteOff ptr 64 ::IO CInt}) err
+  int2 <- (\ptr -> do {peekByteOff ptr 68 ::IO CInt}) err
+  net  <- ptrToNetwork' =<< (\ptr -> do {peekByteOff ptr 72 ::IO (Ptr ())}) err
+  return $ Just $ Error {
+             veCode = toEnum $ fromIntegral code,
+             veDomain = toEnum $ fromIntegral domain,
+             veMessage = message,
+             veLevel = toEnum $ fromIntegral level,
+             veConnect = conn,
+             veDom = dom,
+             veStr1 = str1,
+             veStr2 = str2,
+             veStr3 = str3,
+             veInt1 = fromIntegral int1,
+             veInt2 = fromIntegral int2,
+             veNet = net }
+
+getLastError :: IO (Maybe Error)
+getLastError =
+  getLastError'_ >>= \res ->
+  convertError res >>= \res' ->
+  return (res')
+{-# LINE 97 "System/LibVirt/Errors.chs" #-}
+
+catchVirtError :: IO a -> (Error -> IO b) -> IO (Either b a)
+catchVirtError m f = do
+  (Right `fmap` m) `E.catch` (\e -> Left `fmap` f e)
+
+exceptionOnMinusOne :: CInt -> IO Int
+exceptionOnMinusOne x = do
+  if x == -1
+    then handleError' (fromIntegral x)
+    else return (fromIntegral x)
+
+handleError :: IO a
+handleError = do
+    merr <- getLastError
+    case merr of
+      Just err -> E.throw err
+      Nothing  -> E.throw UnknownError
+
+handleError' :: a -> IO a
+handleError' x = do
+    merr <- getLastError
+    case merr of
+      Just err -> E.throw err
+      Nothing  -> return x
+
+ptrToConnection :: Ptr () -> IO Connection
+ptrToConnection ptr
+  | ptr == nullPtr = handleError
+  | otherwise      = return $ Connection (castPtr ptr)
+
+ptrToConnection' :: Ptr () -> IO Connection
+ptrToConnection' ptr = return $ Connection (castPtr ptr)
+
+connectionToPtr :: Connection -> Ptr ()
+connectionToPtr (Connection ptr) = castPtr ptr
+
+ptrToDomain :: Ptr () -> IO Domain
+ptrToDomain ptr
+  | ptr == nullPtr = handleError
+  | otherwise      = return $ Domain (castPtr ptr)
+
+ptrToDomain' :: Ptr () -> IO Domain
+ptrToDomain' ptr = return $ Domain (castPtr ptr)
+
+domainToPtr :: Domain -> Ptr ()
+domainToPtr (Domain ptr) = castPtr ptr
+
+ptrToNetwork :: Ptr () -> IO Network
+ptrToNetwork ptr
+  | ptr == nullPtr = handleError
+  | otherwise      = return $ Network (castPtr ptr)
+
+ptrToNetwork' :: Ptr () -> IO Network
+ptrToNetwork' ptr = return $ Network (castPtr ptr)
+
+networkToPtr :: Network -> Ptr ()
+networkToPtr (Network ptr) = castPtr ptr
+
+
+foreign import ccall safe "System/LibVirt/Errors.chs.h virGetLastError"
+  getLastError'_ :: (IO (Ptr ()))
diff --git a/System/LibVirt/Foreign.chs b/System/LibVirt/Foreign.chs
--- a/System/LibVirt/Foreign.chs
+++ b/System/LibVirt/Foreign.chs
@@ -247,8 +247,14 @@
 
 {# fun virInitialize as initialize { } -> `Int' exceptionOnMinusOne* #}
 
-{# fun virConnectOpen as openConnection
-    { `String' } -> `Connection' ptrToConnection* #}
+foreign import ccall "&" virConnectAuthPtrDefault :: Ptr (Ptr ())
+
+openConnection :: String -> IO Connection
+openConnection uri =
+  withCString uri $ \str -> do
+    authPtr <- peek virConnectAuthPtrDefault
+    connPtr <- {# call virConnectOpenAuth #} str authPtr 0
+    ptrToConnection connPtr
 
 {# fun virConnectClose as closeConnection
     { connectionToPtr `Connection' } -> `Int' exceptionOnMinusOne* #}
diff --git a/System/LibVirt/Foreign.hs b/System/LibVirt/Foreign.hs
new file mode 100644
--- /dev/null
+++ b/System/LibVirt/Foreign.hs
@@ -0,0 +1,710 @@
+-- GENERATED by C->Haskell Compiler, version 0.16.3 Crystal Seed, 24 Jan 2009 (Haskell)
+-- Edit the ORIGNAL .chs file instead!
+
+
+{-# LINE 1 "System/LibVirt/Foreign.chs" #-}{-# LANGUAGE ForeignFunctionInterface, StandaloneDeriving, DeriveDataTypeable, EmptyDataDecls #-}
+
+
+{-# LINE 3 "System/LibVirt/Foreign.chs" #-}
+
+
+module System.LibVirt.Foreign
+  (-- * Types
+   Connection, Domain, Network,
+   DomainID,
+   DomainInfo (..),
+   DomainState (..),
+   Stream,
+   DomainCreateFlags (..),
+   DomainXMLFlags (..),
+   SecurityLabel (..),
+   SecurityModel (..),
+   NodeInfo (..),
+   SchedParameterType (..),
+   ConnectCredential (..),
+
+   -- * Connection management functions
+   initialize,
+   openConnection, closeConnection,
+
+   -- * Domains management functions
+   runningDomainsCount, definedDomainsCount,
+   runningDomainsIDs, definedDomainsNames,
+   lookupDomainID, lookupDomainName,
+   getDomainInfo, getDomainXML,
+   defineDomainXML, undefineDomain,
+
+   -- * Domains control
+   createDomain, createDomainXML,
+   destroyDomain, 
+   shutdownDomain, rebootDomain,
+   suspendDomain, resumeDomain,
+   saveDomain, restoreDomain,
+   refDomain, freeDomain,
+
+   -- * Networks management
+   getNetworkConnection,
+   runningNetworksCount, definedNetworksCount,
+   runningNetworksNames, definedNetworksNames,
+   lookupNetworkName, lookupNetworkUUID,
+   createNetworkXML, defineNetworkXML,
+   undefineNetwork, destroyNetwork,
+   createNetwork,
+   refNetwork, freeNetwork,
+   getNetworkName,
+   getNetworkXML
+  ) where
+
+import Data.Bits
+import Data.Generics
+import Foreign
+import Foreign.C.Types
+import Foreign.C.String
+
+import System.LibVirt.Internal
+{-# LINE 60 "System/LibVirt/Foreign.chs" #-}
+import System.LibVirt.Errors
+{-# LINE 61 "System/LibVirt/Foreign.chs" #-}
+
+cIntConv = fromIntegral
+
+cuchar2state :: CUChar -> DomainState
+cuchar2state c = toEnum (fromIntegral c)
+
+flags2int :: (Enum f, Num a) => [f] -> a
+flags2int list = fromIntegral $ foldr (.|.) 0 (map fromEnum list)
+
+data DomainInfo = DomainInfo {
+  diState :: DomainState,
+  diMaxMem :: Integer,
+  diMemory :: Integer,
+  diNrVirtCPU :: Int,
+  diCPUTime :: Integer }
+  deriving (Eq, Show)
+
+type DomainInfoPtr = Ptr (DomainInfo)
+{-# LINE 79 "System/LibVirt/Foreign.chs" #-}
+
+data DomainState = DomainNostate
+                 | DomainRunning
+                 | DomainBlocked
+                 | DomainPaused
+                 | DomainShutdown
+                 | DomainShutoff
+                 | DomainCrashed
+                 | DomainLast
+                 deriving (Eq,Show)
+instance Enum DomainState where
+  fromEnum DomainNostate = 0
+  fromEnum DomainRunning = 1
+  fromEnum DomainBlocked = 2
+  fromEnum DomainPaused = 3
+  fromEnum DomainShutdown = 4
+  fromEnum DomainShutoff = 5
+  fromEnum DomainCrashed = 6
+  fromEnum DomainLast = 7
+
+  toEnum 0 = DomainNostate
+  toEnum 1 = DomainRunning
+  toEnum 2 = DomainBlocked
+  toEnum 3 = DomainPaused
+  toEnum 4 = DomainShutdown
+  toEnum 5 = DomainShutoff
+  toEnum 6 = DomainCrashed
+  toEnum 7 = DomainLast
+  toEnum unmatched = error ("DomainState.toEnum: Cannot match " ++ show unmatched)
+
+{-# LINE 81 "System/LibVirt/Foreign.chs" #-}
+data DomainCreateFlags = DomainNone
+                       | DomainStartPaused
+                       | DomainStartAutodestroy
+                       | DomainStartBypassCache
+                       | DomainStartForceBoot
+                       deriving (Eq,Show)
+instance Enum DomainCreateFlags where
+  fromEnum DomainNone = 0
+  fromEnum DomainStartPaused = 1
+  fromEnum DomainStartAutodestroy = 2
+  fromEnum DomainStartBypassCache = 4
+  fromEnum DomainStartForceBoot = 8
+
+  toEnum 0 = DomainNone
+  toEnum 1 = DomainStartPaused
+  toEnum 2 = DomainStartAutodestroy
+  toEnum 4 = DomainStartBypassCache
+  toEnum 8 = DomainStartForceBoot
+  toEnum unmatched = error ("DomainCreateFlags.toEnum: Cannot match " ++ show unmatched)
+
+{-# LINE 82 "System/LibVirt/Foreign.chs" #-}
+data DomainXMLFlags = DomainXmlSecure
+                    | DomainXmlInactive
+                    | DomainXmlUpdateCpu
+                    deriving (Eq,Show)
+instance Enum DomainXMLFlags where
+  fromEnum DomainXmlSecure = 1
+  fromEnum DomainXmlInactive = 2
+  fromEnum DomainXmlUpdateCpu = 4
+
+  toEnum 1 = DomainXmlSecure
+  toEnum 2 = DomainXmlInactive
+  toEnum 4 = DomainXmlUpdateCpu
+  toEnum unmatched = error ("DomainXMLFlags.toEnum: Cannot match " ++ show unmatched)
+
+{-# LINE 83 "System/LibVirt/Foreign.chs" #-}
+
+data NetworkXMLFlags = NetworkXML
+  deriving (Eq, Show, Enum)
+
+newtype Stream = Stream (Ptr (Stream))
+{-# LINE 88 "System/LibVirt/Foreign.chs" #-}
+
+data SecurityLabel = SecurityLabel {
+  slLabel :: String,
+  slEnforcing :: Int }
+  deriving (Eq, Show)
+
+type SecurityLabelPtr = Ptr (SecurityLabel)
+{-# LINE 95 "System/LibVirt/Foreign.chs" #-}
+
+data SecurityModel = SecurityModel {
+  smModel :: String,
+  smDOI :: String }
+  deriving (Eq, Show)
+
+type SecurityModelPtr = Ptr (SecurityModel)
+{-# LINE 102 "System/LibVirt/Foreign.chs" #-}
+
+data NodeInfo = NodeInfo {
+  niModel :: String,
+  niMemory :: CULong,
+  niCPUs :: CUInt,
+  niMHz :: CUInt,
+  niNodes :: CUInt,
+  niSockets :: CUInt,
+  niCores :: CUInt,
+  niThreads :: CUInt }
+  deriving (Eq, Show)
+
+type NodeInfoPtr = Ptr (NodeInfo)
+{-# LINE 115 "System/LibVirt/Foreign.chs" #-}
+
+data SchedParameterType = DomainSchedFieldInt
+                        | DomainSchedFieldUint
+                        | DomainSchedFieldLlong
+                        | DomainSchedFieldUllong
+                        | DomainSchedFieldDouble
+                        | DomainSchedFieldBoolean
+                        deriving (Eq,Show)
+instance Enum SchedParameterType where
+  fromEnum DomainSchedFieldInt = 1
+  fromEnum DomainSchedFieldUint = 2
+  fromEnum DomainSchedFieldLlong = 3
+  fromEnum DomainSchedFieldUllong = 4
+  fromEnum DomainSchedFieldDouble = 5
+  fromEnum DomainSchedFieldBoolean = 6
+
+  toEnum 1 = DomainSchedFieldInt
+  toEnum 2 = DomainSchedFieldUint
+  toEnum 3 = DomainSchedFieldLlong
+  toEnum 4 = DomainSchedFieldUllong
+  toEnum 5 = DomainSchedFieldDouble
+  toEnum 6 = DomainSchedFieldBoolean
+  toEnum unmatched = error ("SchedParameterType.toEnum: Cannot match " ++ show unmatched)
+
+{-# LINE 117 "System/LibVirt/Foreign.chs" #-}
+
+data ConnectCredential = ConnectCredential {
+  ccType :: Int,
+  ccPrompt :: String,
+  ccChallenge :: String,
+  ccDefresult :: String,
+  ccResult :: String,
+  ccResultLen :: Integer }
+  deriving (Eq, Show)
+
+type ConnectCredentialPtr = Ptr (ConnectCredential)
+{-# LINE 128 "System/LibVirt/Foreign.chs" #-}
+
+initialize :: IO (Int)
+initialize =
+  initialize'_ >>= \res ->
+  exceptionOnMinusOne res >>= \res' ->
+  return (res')
+{-# LINE 130 "System/LibVirt/Foreign.chs" #-}
+
+openConnection :: String -> IO (Connection)
+openConnection a1 =
+  withCString a1 $ \a1' -> 
+  openConnection'_ a1' >>= \res ->
+  ptrToConnection res >>= \res' ->
+  return (res')
+{-# LINE 133 "System/LibVirt/Foreign.chs" #-}
+
+closeConnection :: Connection -> IO (Int)
+closeConnection a1 =
+  let {a1' = connectionToPtr a1} in 
+  closeConnection'_ a1' >>= \res ->
+  exceptionOnMinusOne res >>= \res' ->
+  return (res')
+{-# LINE 136 "System/LibVirt/Foreign.chs" #-}
+
+runningDomainsCount :: Connection -> IO (Int)
+runningDomainsCount a1 =
+  let {a1' = connectionToPtr a1} in 
+  runningDomainsCount'_ a1' >>= \res ->
+  exceptionOnMinusOne res >>= \res' ->
+  return (res')
+{-# LINE 139 "System/LibVirt/Foreign.chs" #-}
+
+type DomainID = CInt
+
+runningDomainsIDs :: Connection -> IO [DomainID]
+runningDomainsIDs conn = do
+  cn <- virConnectNumOfDomains (connectionToPtr conn)
+  let n = fromIntegral cn
+  r <- allocaArray n $ \arr -> do
+          r <- virConnectListDomains
+{-# LINE 148 "System/LibVirt/Foreign.chs" #-}
+                  (connectionToPtr conn) arr cn
+          peekArray n arr
+  return r
+
+definedDomainsNames :: Connection -> IO [String]
+definedDomainsNames conn = do
+  cn <- virConnectNumOfDefinedDomains (connectionToPtr conn)
+  let n = fromIntegral cn
+  allocaArray n $ \nptr -> do
+    virConnectListDefinedDomains
+{-# LINE 158 "System/LibVirt/Foreign.chs" #-}
+        (connectionToPtr conn) nptr cn
+    mapM peekCString =<< peekArray n nptr
+
+lookupDomainID :: Connection -> DomainID -> IO (Domain)
+lookupDomainID a1 a2 =
+  let {a1' = connectionToPtr a1} in 
+  let {a2' = id a2} in 
+  lookupDomainID'_ a1' a2' >>= \res ->
+  ptrToDomain res >>= \res' ->
+  return (res')
+{-# LINE 164 "System/LibVirt/Foreign.chs" #-}
+
+lookupDomainName :: Connection -> String -> IO (Domain)
+lookupDomainName a1 a2 =
+  let {a1' = connectionToPtr a1} in 
+  withCString a2 $ \a2' -> 
+  lookupDomainName'_ a1' a2' >>= \res ->
+  ptrToDomain res >>= \res' ->
+  return (res')
+{-# LINE 168 "System/LibVirt/Foreign.chs" #-}
+
+definedDomainsCount :: Connection -> IO (Int)
+definedDomainsCount a1 =
+  let {a1' = connectionToPtr a1} in 
+  definedDomainsCount'_ a1' >>= \res ->
+  exceptionOnMinusOne res >>= \res' ->
+  return (res')
+{-# LINE 171 "System/LibVirt/Foreign.chs" #-}
+
+getDomainInfo :: Domain -> IO DomainInfo
+getDomainInfo dptr = do
+  allocaBytes 40 $ \iptr -> do
+         i <- virDomainGetInfo (domainToPtr dptr) iptr
+         state   <- (\ptr -> do {peekByteOff ptr 0 ::IO CUChar})     iptr
+         maxmem  <- (\ptr -> do {peekByteOff ptr 8 ::IO CULong})    iptr
+         memory  <- (\ptr -> do {peekByteOff ptr 16 ::IO CULong})    iptr
+         ncpus   <- (\ptr -> do {peekByteOff ptr 24 ::IO CUShort}) iptr
+         cputime <- (\ptr -> do {peekByteOff ptr 32 ::IO CULLong})   iptr
+         return $ DomainInfo {
+                    diState     = cuchar2state state,
+                    diMaxMem    = fromIntegral maxmem,
+                    diMemory    = fromIntegral memory,
+                    diNrVirtCPU = fromIntegral ncpus,
+                    diCPUTime   = fromIntegral cputime }
+
+defineDomainXML :: Connection -> String -> IO (Domain)
+defineDomainXML a1 a2 =
+  let {a1' = connectionToPtr a1} in 
+  withCString a2 $ \a2' -> 
+  defineDomainXML'_ a1' a2' >>= \res ->
+  ptrToDomain res >>= \res' ->
+  return (res')
+{-# LINE 191 "System/LibVirt/Foreign.chs" #-}
+
+undefineDomain :: Domain -> IO (Int)
+undefineDomain a1 =
+  let {a1' = domainToPtr a1} in 
+  undefineDomain'_ a1' >>= \res ->
+  exceptionOnMinusOne res >>= \res' ->
+  return (res')
+{-# LINE 194 "System/LibVirt/Foreign.chs" #-}
+
+createDomain :: Domain -> IO (Int)
+createDomain a1 =
+  let {a1' = domainToPtr a1} in 
+  createDomain'_ a1' >>= \res ->
+  exceptionOnMinusOne res >>= \res' ->
+  return (res')
+{-# LINE 197 "System/LibVirt/Foreign.chs" #-}
+
+createDomainXML :: Connection -> String -> [DomainCreateFlags] -> IO (Domain)
+createDomainXML a1 a2 a3 =
+  let {a1' = connectionToPtr a1} in 
+  withCString a2 $ \a2' -> 
+  let {a3' = flags2int a3} in 
+  createDomainXML'_ a1' a2' a3' >>= \res ->
+  ptrToDomain res >>= \res' ->
+  return (res')
+{-# LINE 202 "System/LibVirt/Foreign.chs" #-}
+
+getDomainXML :: Domain -> [DomainXMLFlags] -> IO (String)
+getDomainXML a1 a2 =
+  let {a1' = domainToPtr a1} in 
+  let {a2' = flags2int a2} in 
+  getDomainXML'_ a1' a2' >>= \res ->
+  peekCString res >>= \res' ->
+  return (res')
+{-# LINE 206 "System/LibVirt/Foreign.chs" #-}
+
+shutdownDomain :: Domain -> IO (Int)
+shutdownDomain a1 =
+  let {a1' = domainToPtr a1} in 
+  shutdownDomain'_ a1' >>= \res ->
+  exceptionOnMinusOne res >>= \res' ->
+  return (res')
+{-# LINE 209 "System/LibVirt/Foreign.chs" #-}
+
+rebootDomain :: Domain -> CUInt -> IO (Int)
+rebootDomain a1 a2 =
+  let {a1' = domainToPtr a1} in 
+  let {a2' = id a2} in 
+  rebootDomain'_ a1' a2' >>= \res ->
+  exceptionOnMinusOne res >>= \res' ->
+  return (res')
+{-# LINE 213 "System/LibVirt/Foreign.chs" #-}
+
+destroyDomain :: Domain -> IO (Int)
+destroyDomain a1 =
+  let {a1' = domainToPtr a1} in 
+  destroyDomain'_ a1' >>= \res ->
+  exceptionOnMinusOne res >>= \res' ->
+  return (res')
+{-# LINE 216 "System/LibVirt/Foreign.chs" #-}
+
+refDomain :: Domain -> IO (Int)
+refDomain a1 =
+  let {a1' = domainToPtr a1} in 
+  refDomain'_ a1' >>= \res ->
+  exceptionOnMinusOne res >>= \res' ->
+  return (res')
+{-# LINE 219 "System/LibVirt/Foreign.chs" #-}
+
+freeDomain :: Domain -> IO (Int)
+freeDomain a1 =
+  let {a1' = domainToPtr a1} in 
+  freeDomain'_ a1' >>= \res ->
+  exceptionOnMinusOne res >>= \res' ->
+  return (res')
+{-# LINE 222 "System/LibVirt/Foreign.chs" #-}
+
+suspendDomain :: Domain -> IO (Int)
+suspendDomain a1 =
+  let {a1' = domainToPtr a1} in 
+  suspendDomain'_ a1' >>= \res ->
+  exceptionOnMinusOne res >>= \res' ->
+  return (res')
+{-# LINE 225 "System/LibVirt/Foreign.chs" #-}
+
+resumeDomain :: Domain -> IO (Int)
+resumeDomain a1 =
+  let {a1' = domainToPtr a1} in 
+  resumeDomain'_ a1' >>= \res ->
+  exceptionOnMinusOne res >>= \res' ->
+  return (res')
+{-# LINE 228 "System/LibVirt/Foreign.chs" #-}
+
+saveDomain :: Domain -> String -> IO (Int)
+saveDomain a1 a2 =
+  let {a1' = domainToPtr a1} in 
+  withCString a2 $ \a2' -> 
+  saveDomain'_ a1' a2' >>= \res ->
+  exceptionOnMinusOne res >>= \res' ->
+  return (res')
+{-# LINE 232 "System/LibVirt/Foreign.chs" #-}
+
+restoreDomain :: Connection -> String -> IO (Int)
+restoreDomain a1 a2 =
+  let {a1' = connectionToPtr a1} in 
+  withCString a2 $ \a2' -> 
+  restoreDomain'_ a1' a2' >>= \res ->
+  exceptionOnMinusOne res >>= \res' ->
+  return (res')
+{-# LINE 236 "System/LibVirt/Foreign.chs" #-}
+
+getNetworkConnection :: Network -> IO (Connection)
+getNetworkConnection a1 =
+  let {a1' = networkToPtr a1} in 
+  getNetworkConnection'_ a1' >>= \res ->
+  ptrToConnection res >>= \res' ->
+  return (res')
+{-# LINE 239 "System/LibVirt/Foreign.chs" #-}
+
+runningNetworksCount :: Connection -> IO (Int)
+runningNetworksCount a1 =
+  let {a1' = connectionToPtr a1} in 
+  runningNetworksCount'_ a1' >>= \res ->
+  exceptionOnMinusOne res >>= \res' ->
+  return (res')
+{-# LINE 242 "System/LibVirt/Foreign.chs" #-}
+
+runningNetworksNames :: Connection -> IO [String]
+runningNetworksNames conn = do
+  cn <- virConnectNumOfNetworks (connectionToPtr conn)
+  let n = fromIntegral cn
+  allocaArray n $ \nptr -> do
+    virConnectListNetworks (connectionToPtr conn) nptr cn
+    mapM peekCString =<< peekArray n nptr
+
+definedNetworksCount :: Connection -> IO (Int)
+definedNetworksCount a1 =
+  let {a1' = connectionToPtr a1} in 
+  definedNetworksCount'_ a1' >>= \res ->
+  exceptionOnMinusOne res >>= \res' ->
+  return (res')
+{-# LINE 253 "System/LibVirt/Foreign.chs" #-}
+
+definedNetworksNames :: Connection -> IO [String]
+definedNetworksNames conn = do
+  cn <- virConnectNumOfDefinedNetworks (connectionToPtr conn)
+  let n = fromIntegral cn
+  allocaArray n $ \nptr -> do
+    virConnectListDefinedNetworks (connectionToPtr conn) nptr cn
+    mapM peekCString =<< peekArray n nptr
+
+lookupNetworkName :: Connection -> String -> IO (Network)
+lookupNetworkName a1 a2 =
+  let {a1' = connectionToPtr a1} in 
+  withCString a2 $ \a2' -> 
+  lookupNetworkName'_ a1' a2' >>= \res ->
+  ptrToNetwork res >>= \res' ->
+  return (res')
+{-# LINE 264 "System/LibVirt/Foreign.chs" #-}
+
+withCUString :: String -> (Ptr CUChar -> IO a) -> IO a
+withCUString str fn = withCString str (fn . castPtr)
+
+lookupNetworkUUID :: Connection -> String -> IO (Network)
+lookupNetworkUUID a1 a2 =
+  let {a1' = connectionToPtr a1} in 
+  withCUString a2 $ \a2' -> 
+  lookupNetworkUUID'_ a1' a2' >>= \res ->
+  ptrToNetwork res >>= \res' ->
+  return (res')
+{-# LINE 270 "System/LibVirt/Foreign.chs" #-}
+
+createNetworkXML :: Connection -> String -> IO (Network)
+createNetworkXML a1 a2 =
+  let {a1' = connectionToPtr a1} in 
+  withCString a2 $ \a2' -> 
+  createNetworkXML'_ a1' a2' >>= \res ->
+  ptrToNetwork res >>= \res' ->
+  return (res')
+{-# LINE 273 "System/LibVirt/Foreign.chs" #-}
+
+defineNetworkXML :: Connection -> String -> IO (Network)
+defineNetworkXML a1 a2 =
+  let {a1' = connectionToPtr a1} in 
+  withCString a2 $ \a2' -> 
+  defineNetworkXML'_ a1' a2' >>= \res ->
+  ptrToNetwork res >>= \res' ->
+  return (res')
+{-# LINE 276 "System/LibVirt/Foreign.chs" #-}
+
+undefineNetwork :: Network -> IO (Int)
+undefineNetwork a1 =
+  let {a1' = networkToPtr a1} in 
+  undefineNetwork'_ a1' >>= \res ->
+  exceptionOnMinusOne res >>= \res' ->
+  return (res')
+{-# LINE 279 "System/LibVirt/Foreign.chs" #-}
+
+createNetwork :: Network -> IO (Int)
+createNetwork a1 =
+  let {a1' = networkToPtr a1} in 
+  createNetwork'_ a1' >>= \res ->
+  exceptionOnMinusOne res >>= \res' ->
+  return (res')
+{-# LINE 282 "System/LibVirt/Foreign.chs" #-}
+
+destroyNetwork :: Network -> IO (Int)
+destroyNetwork a1 =
+  let {a1' = networkToPtr a1} in 
+  destroyNetwork'_ a1' >>= \res ->
+  exceptionOnMinusOne res >>= \res' ->
+  return (res')
+{-# LINE 285 "System/LibVirt/Foreign.chs" #-}
+
+refNetwork :: Network -> IO (Int)
+refNetwork a1 =
+  let {a1' = networkToPtr a1} in 
+  refNetwork'_ a1' >>= \res ->
+  exceptionOnMinusOne res >>= \res' ->
+  return (res')
+{-# LINE 288 "System/LibVirt/Foreign.chs" #-}
+
+freeNetwork :: Network -> IO (Int)
+freeNetwork a1 =
+  let {a1' = networkToPtr a1} in 
+  freeNetwork'_ a1' >>= \res ->
+  exceptionOnMinusOne res >>= \res' ->
+  return (res')
+{-# LINE 291 "System/LibVirt/Foreign.chs" #-}
+
+getNetworkName :: Network -> IO (String)
+getNetworkName a1 =
+  let {a1' = networkToPtr a1} in 
+  getNetworkName'_ a1' >>= \res ->
+  peekCString res >>= \res' ->
+  return (res')
+{-# LINE 294 "System/LibVirt/Foreign.chs" #-}
+
+getNetworkXML :: Network -> [NetworkXMLFlags] -> IO (String)
+getNetworkXML a1 a2 =
+  let {a1' = networkToPtr a1} in 
+  let {a2' = flags2int a2} in 
+  getNetworkXML'_ a1' a2' >>= \res ->
+  peekCString res >>= \res' ->
+  return (res')
+{-# LINE 298 "System/LibVirt/Foreign.chs" #-}
+
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virInitialize"
+  initialize'_ :: (IO CInt)
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virConnectOpen"
+  openConnection'_ :: ((Ptr CChar) -> (IO (Ptr ())))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virConnectClose"
+  closeConnection'_ :: ((Ptr ()) -> (IO CInt))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virConnectNumOfDomains"
+  runningDomainsCount'_ :: ((Ptr ()) -> (IO CInt))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virConnectNumOfDomains"
+  virConnectNumOfDomains :: ((Ptr ()) -> (IO CInt))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virConnectListDomains"
+  virConnectListDomains :: ((Ptr ()) -> ((Ptr CInt) -> (CInt -> (IO CInt))))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virConnectNumOfDefinedDomains"
+  virConnectNumOfDefinedDomains :: ((Ptr ()) -> (IO CInt))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virConnectListDefinedDomains"
+  virConnectListDefinedDomains :: ((Ptr ()) -> ((Ptr (Ptr CChar)) -> (CInt -> (IO CInt))))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virDomainLookupByID"
+  lookupDomainID'_ :: ((Ptr ()) -> (CInt -> (IO (Ptr ()))))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virDomainLookupByName"
+  lookupDomainName'_ :: ((Ptr ()) -> ((Ptr CChar) -> (IO (Ptr ()))))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virConnectNumOfDefinedDomains"
+  definedDomainsCount'_ :: ((Ptr ()) -> (IO CInt))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virDomainGetInfo"
+  virDomainGetInfo :: ((Ptr ()) -> ((DomainInfoPtr) -> (IO CInt)))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virDomainDefineXML"
+  defineDomainXML'_ :: ((Ptr ()) -> ((Ptr CChar) -> (IO (Ptr ()))))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virDomainUndefine"
+  undefineDomain'_ :: ((Ptr ()) -> (IO CInt))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virDomainCreate"
+  createDomain'_ :: ((Ptr ()) -> (IO CInt))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virDomainCreateXML"
+  createDomainXML'_ :: ((Ptr ()) -> ((Ptr CChar) -> (CUInt -> (IO (Ptr ())))))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virDomainGetXMLDesc"
+  getDomainXML'_ :: ((Ptr ()) -> (CUInt -> (IO (Ptr CChar))))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virDomainShutdown"
+  shutdownDomain'_ :: ((Ptr ()) -> (IO CInt))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virDomainReboot"
+  rebootDomain'_ :: ((Ptr ()) -> (CUInt -> (IO CInt)))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virDomainDestroy"
+  destroyDomain'_ :: ((Ptr ()) -> (IO CInt))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virDomainRef"
+  refDomain'_ :: ((Ptr ()) -> (IO CInt))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virDomainFree"
+  freeDomain'_ :: ((Ptr ()) -> (IO CInt))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virDomainSuspend"
+  suspendDomain'_ :: ((Ptr ()) -> (IO CInt))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virDomainResume"
+  resumeDomain'_ :: ((Ptr ()) -> (IO CInt))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virDomainSave"
+  saveDomain'_ :: ((Ptr ()) -> ((Ptr CChar) -> (IO CInt)))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virDomainRestore"
+  restoreDomain'_ :: ((Ptr ()) -> ((Ptr CChar) -> (IO CInt)))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virNetworkGetConnect"
+  getNetworkConnection'_ :: ((Ptr ()) -> (IO (Ptr ())))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virConnectNumOfNetworks"
+  runningNetworksCount'_ :: ((Ptr ()) -> (IO CInt))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virConnectNumOfNetworks"
+  virConnectNumOfNetworks :: ((Ptr ()) -> (IO CInt))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virConnectListNetworks"
+  virConnectListNetworks :: ((Ptr ()) -> ((Ptr (Ptr CChar)) -> (CInt -> (IO CInt))))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virConnectNumOfDefinedNetworks"
+  definedNetworksCount'_ :: ((Ptr ()) -> (IO CInt))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virConnectNumOfDefinedNetworks"
+  virConnectNumOfDefinedNetworks :: ((Ptr ()) -> (IO CInt))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virConnectListDefinedNetworks"
+  virConnectListDefinedNetworks :: ((Ptr ()) -> ((Ptr (Ptr CChar)) -> (CInt -> (IO CInt))))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virNetworkLookupByName"
+  lookupNetworkName'_ :: ((Ptr ()) -> ((Ptr CChar) -> (IO (Ptr ()))))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virNetworkLookupByUUID"
+  lookupNetworkUUID'_ :: ((Ptr ()) -> ((Ptr CUChar) -> (IO (Ptr ()))))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virNetworkCreateXML"
+  createNetworkXML'_ :: ((Ptr ()) -> ((Ptr CChar) -> (IO (Ptr ()))))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virNetworkDefineXML"
+  defineNetworkXML'_ :: ((Ptr ()) -> ((Ptr CChar) -> (IO (Ptr ()))))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virNetworkUndefine"
+  undefineNetwork'_ :: ((Ptr ()) -> (IO CInt))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virNetworkCreate"
+  createNetwork'_ :: ((Ptr ()) -> (IO CInt))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virNetworkDestroy"
+  destroyNetwork'_ :: ((Ptr ()) -> (IO CInt))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virNetworkRef"
+  refNetwork'_ :: ((Ptr ()) -> (IO CInt))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virNetworkFree"
+  freeNetwork'_ :: ((Ptr ()) -> (IO CInt))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virNetworkGetName"
+  getNetworkName'_ :: ((Ptr ()) -> (IO (Ptr CChar)))
+
+foreign import ccall safe "System/LibVirt/Foreign.chs.h virNetworkGetXMLDesc"
+  getNetworkXML'_ :: ((Ptr ()) -> (CUInt -> (IO (Ptr CChar))))
diff --git a/System/LibVirt/Internal.hs b/System/LibVirt/Internal.hs
new file mode 100644
--- /dev/null
+++ b/System/LibVirt/Internal.hs
@@ -0,0 +1,51 @@
+-- GENERATED by C->Haskell Compiler, version 0.16.3 Crystal Seed, 24 Jan 2009 (Haskell)
+-- Edit the ORIGNAL .chs file instead!
+
+
+{-# LINE 1 "System/LibVirt/Internal.chs" #-}{-# LANGUAGE ForeignFunctionInterface, StandaloneDeriving, DeriveDataTypeable #-}
+
+
+{-# LINE 3 "System/LibVirt/Internal.chs" #-}
+
+
+-- | Internal types definitions and low-level functions.
+-- This module is not supposed to be imported by client code.
+module System.LibVirt.Internal
+  (Connection (..), Domain (..), Network (..)
+  ) where
+
+import Data.Generics
+import Foreign
+import Foreign.C.Types
+import Foreign.C.String
+
+newtype Connection = Connection (Ptr (Connection))
+{-# LINE 18 "System/LibVirt/Internal.chs" #-}
+
+deriving instance Eq Connection
+deriving instance Data Connection
+deriving instance Typeable Connection
+
+instance Show Connection where
+  show (Connection ptr) = "<Connection: " ++ show ptr ++ ">"
+
+newtype Domain = Domain (Ptr (Domain))
+{-# LINE 27 "System/LibVirt/Internal.chs" #-}
+
+deriving instance Eq Domain
+deriving instance Data Domain
+deriving instance Typeable Domain
+
+instance Show Domain where
+  show (Domain ptr) = "<Domain: " ++ show ptr ++ ">"
+
+newtype Network = Network (Ptr (Network))
+{-# LINE 36 "System/LibVirt/Internal.chs" #-}
+
+deriving instance Eq Network
+deriving instance Data Network
+deriving instance Typeable Network
+
+instance Show Network where
+  show (Network ptr) = "<Network: " ++ show ptr ++ ">"
+
diff --git a/libvirt-hs.cabal b/libvirt-hs.cabal
--- a/libvirt-hs.cabal
+++ b/libvirt-hs.cabal
@@ -1,5 +1,5 @@
 Name:                libvirt-hs
-Version:             0.2.0
+Version:             0.2.1
 
 Synopsis:            FFI bindings to libvirt virtualization API (http://libvirt.org)
 
