diff --git a/ChangeLog.md b/ChangeLog.md
new file mode 100644
--- /dev/null
+++ b/ChangeLog.md
@@ -0,0 +1,7 @@
+# Changelog for koji-hs
+
+`koji` uses [PVP Versioning](https://pvp.haskell.org).
+
+## 0.0.1
+- First Hackage release with higher level Distribution.Koji and
+  low level Distribution.Koji.API modules. Only query procedures.
diff --git a/LICENSE b/LICENSE
new file mode 100644
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,339 @@
+                    GNU GENERAL PUBLIC LICENSE
+                       Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+                            Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+                    GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+                            NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+                     END OF TERMS AND CONDITIONS
+
+            How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License along
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) year name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  <signature of Ty Coon>, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.
diff --git a/README.md b/README.md
new file mode 100644
--- /dev/null
+++ b/README.md
@@ -0,0 +1,32 @@
+# Koji XML-RPC binding for Haskell
+
+[![GitHub CI](https://github.com/juhp/koji-hs/workflows/build/badge.svg)](https://github.com/juhp/koji-hs/actions)
+[![Hackage](https://img.shields.io/hackage/v/koji.svg?logo=haskell)](https://hackage.haskell.org/package/koji)
+[![Stackage Lts](http://stackage.org/package/koji/badge/lts)](http://stackage.org/lts/package/koji)
+[![Stackage Nightly](http://stackage.org/package/koji/badge/nightly)](http://stackage.org/nightly/package/koji)
+[![GPL-2 license](https://img.shields.io/badge/license-GPL--2-blue.svg)](LICENSE)
+
+[Koji](https://pagure.io/koji/) is a distributed RPM-based buildsystem.
+
+This library provides Haskell bindings to the Koji XML-RPC API.
+
+It is a WIP: currently only querying koji is working,
+ie login authentication or building etc is supported yet.
+
+## Building
+
+Build with `stack` or `cabal new-build`.
+
+## Usage
+
+Due to haxr using HsOpenSSL, programs using this library
+need to be linked with `ghc-options: -threaded`, otherwise
+the ghc RTS will complain with a runtime error.
+
+See the Haddock documentation for more details.
+
+## Projects using koji-hs
+
+- [fbrnch](https://github.com/juhp/fbrnch/)
+- [koji-progress](https://github.com/juhp/koji-progress)
+- [pkgtreediff](https://github.com/juhp/pkgtreediff/)
diff --git a/koji.cabal b/koji.cabal
new file mode 100644
--- /dev/null
+++ b/koji.cabal
@@ -0,0 +1,54 @@
+name:                koji
+version:             0.0.1
+synopsis:            Koji buildsystem XML-RPC API bindings
+description:
+        This library provides Haskell bindings to the Koji XML RPC API.
+        Koji is a distributed rpm buildsystem used by Fedora, Centos,
+        Red Hat, and other projects. See <https://pagure.io/koji/>.
+category:            Network
+homepage:            https://github.com/juhp/koji-hs
+bug-reports:         https://github.com/juhp/koji-hs/issues
+license:             GPL-2
+license-file:        LICENSE
+author:              Jens Petersen <petersen@redhat.com>
+maintainer:          Jens Petersen <petersen@redhat.com>
+copyright:           2020-2021 Jens Petersen
+build-type:          Simple
+cabal-version:       1.18
+extra-doc-files:     README.md
+                     ChangeLog.md
+tested-with:         GHC == 8.0.2
+                   , GHC == 8.2.2
+                   , GHC == 8.4.4
+                   , GHC == 8.6.5
+                   , GHC == 8.8.4
+                   , GHC == 8.10.4
+
+source-repository head
+  type:                git
+  location:            https://github.com/juhp/koji-hs.git
+
+library
+  hs-source-dirs:      src
+  exposed-modules:     Distribution.Koji
+                       Distribution.Koji.API
+
+  build-depends:       base >= 4 && < 5
+                     , haxr >= 3000.11.4
+                     , mtl
+  default-language:    Haskell2010
+
+  ghc-options:         -Wall
+  if impl(ghc >= 8.0)
+    ghc-options:       -Wcompat
+                       -Widentities
+                       -Wincomplete-uni-patterns
+                       -Wincomplete-record-updates
+                       -Wredundant-constraints
+  if impl(ghc >= 8.2)
+    ghc-options:       -fhide-source-paths
+  if impl(ghc >= 8.4)
+    ghc-options:       -Wmissing-export-lists
+                       -Wpartial-fields
+  if impl(ghc >= 8.10)
+    ghc-options:       -Wunused-packages
diff --git a/src/Distribution/Koji.hs b/src/Distribution/Koji.hs
new file mode 100644
--- /dev/null
+++ b/src/Distribution/Koji.hs
@@ -0,0 +1,373 @@
+{-|
+A library for accessing a Koji hub via its XMLRPC API.
+-}
+
+module Distribution.Koji
+       ( BuildID(..)
+       , BuildInfo(..)
+       , buildIDInfo
+       , fedoraKojiHub
+       , centosKojiHub
+       , kojiBuildTags
+       , kojiBuildTarget
+       , kojiGetBuildID
+       , kojiGetBuildState
+       , kojiGetBuildTaskID
+       , kojiGetCurrentRepo
+       , kojiGetRepo
+       , kojiGetTaskInfo
+       , kojiGetTaskChildren
+       , kojiGetTaskState
+       , kojiGetUserID
+       , kojiLatestBuild
+       , kojiLatestBuildRepo
+       , kojiListSideTags
+       , kojiListTaskIDs
+       , kojiUserBuildTasks
+       , KojiBuild(..)
+       , kojiListTaggedBuilds
+       , PackageID(..)
+       , TagID(..)
+       , TaskID(..)
+       , UserID(..)
+       , displayID
+       , getID
+       , readID
+       , readID'
+       , TaskState(..)
+       , getTaskState
+       , openTaskStates
+       , openTaskValues
+       , readTaskState
+       , BuildState(..)
+       , readBuildState
+       , Struct
+       , lookupStruct
+       , Value (..)
+       , getInt
+       , getString
+       , RepoState(..)
+       , readRepoState
+       )
+where
+
+import qualified Data.List as L
+import Data.Maybe
+import Network.XmlRpc.Internals
+
+import Distribution.Koji.API
+
+-- | A class for various id's: taskid, tagid, buildid, packageid, etc
+class ID a where
+  getID :: a -> Int
+  mkID :: Int -> a
+
+displayID :: ID a => a -> String
+displayID = show . getID
+
+-- FIXME rename to structID ?
+readID :: ID a => Struct -> Maybe a
+readID st = lookup "id" st >>= fmap mkID . getInt
+
+readID' :: Struct -> Maybe Int
+readID' st = lookup "id" st >>= getInt
+
+-- FIXME rename to valueInt ?
+getInt :: Value -> Maybe Int
+getInt (ValueInt i) = Just i
+getInt _ = Nothing
+
+getString :: Value -> Maybe String
+getString (ValueString i) = Just i
+getString _ = Nothing
+
+newtype TaskID = TaskId Int
+  deriving Show
+
+instance ID TaskID where
+  getID (TaskId i) = i
+  mkID = TaskId
+
+newtype TagID = TagId Int
+  deriving Show
+
+instance ID TagID where
+  getID (TagId i) = i
+  mkID = TagId
+
+newtype UserID = UserId Int
+  deriving Show
+
+instance ID UserID where
+  getID (UserId i) = i
+  mkID = UserId
+
+newtype BuildID = BuildId Int
+
+instance ID BuildID where
+  getID (BuildId i) = i
+  mkID = BuildId
+
+newtype PackageID = PackageId Int
+
+instance ID PackageID where
+  getID (PackageId i) = i
+  mkID = PackageId
+
+newtype BuildrootID = BuildrootId Int
+
+instance ID BuildrootID where
+  getID (BuildrootId i) = i
+  mkID = BuildrootId
+
+data BuildInfo = BuildInfoID Int | BuildInfoNVR String
+
+-- | map a BuildInfo into a Info
+buildInfo :: BuildInfo -> Info
+buildInfo (BuildInfoID bid) = InfoID bid
+buildInfo (BuildInfoNVR nvr) = InfoString nvr
+
+-- | map a buildid into a buildinfo
+buildIDInfo :: BuildID -> BuildInfo
+buildIDInfo (BuildId bid) = BuildInfoID bid
+
+-- | main Fedora Koji Hub
+fedoraKojiHub :: String
+fedoraKojiHub = "https://koji.fedoraproject.org/kojihub"
+
+-- | Centos Koji mbox Hub
+centosKojiHub :: String
+centosKojiHub = "https://koji.mbox.centos.org/kojihub"
+
+-- | Get the buildid of an nvr build
+kojiGetBuildID :: String -- ^ hub url
+               -> String -- ^ NVR
+               -> IO (Maybe BuildID)
+kojiGetBuildID hubUrl nvr =
+  ((fmap BuildId . lookupStruct "id") =<<) <$> getBuild hubUrl (InfoString nvr)
+
+-- | Get the task of an nvr build
+kojiGetBuildTaskID :: String -- ^ hub url
+                   -> String -- ^ NVR
+                   -> IO (Maybe TaskID)
+kojiGetBuildTaskID hubUrl nvr =
+  ((fmap TaskId . lookupStruct "task_id") =<<) <$> getBuild hubUrl (InfoString nvr)
+
+-- | List tasks filtered by query options
+kojiListTaskIDs :: String -- ^ hub url
+                -> Struct -- ^ options
+                -> Struct -- ^ query opts
+                -> IO [TaskID]
+kojiListTaskIDs hubUrl opts qopts =
+  mapMaybe readID <$> listTasks hubUrl opts qopts
+
+-- | List the open tasks of a user (matching source/target)
+kojiUserBuildTasks :: String -- ^ hub url
+                   -> UserID
+                   -> Maybe String -- ^ source
+                   -> Maybe String -- ^ target
+                   -> IO [TaskID]
+kojiUserBuildTasks hubUrl userid msource mtarget = do
+  tasks <- listTasks hubUrl [("owner",ValueInt (getID userid)),("method",ValueString "build"),("state",openTaskValues)] []
+  return $ map TaskId . mapMaybe (lookupStruct "id") $ filter isTheBuild tasks
+  where
+    isTheBuild :: Struct -> Bool
+    isTheBuild st =
+      let mreq = lookupStruct "request" st in
+        case mreq of
+          Nothing -> False
+          Just req ->
+            maybe True (`L.isInfixOf` req) msource &&
+            maybe True (\ target -> ("<value><string>" ++ target ++ "</string></value>") `L.isInfixOf` req) mtarget
+
+-- getTagID :: String -- ^ tag
+--          -> IO TagID
+-- getTagID tag =
+--   TagId <$> koji "getTagID" tag
+
+-- | Get the userid for the named user
+kojiGetUserID :: String -- ^ hub url
+              -> String -- ^ user
+              -> IO (Maybe UserID)
+kojiGetUserID hubUrl name = do
+  res <- getUser hubUrl (InfoString name) False
+  return $ readID =<< res
+
+-- | Get the tags of a build
+kojiBuildTags :: String  -- ^ hub url
+              -> BuildInfo
+              -> IO [String]
+kojiBuildTags hubUrl buildinfo = do
+  lst <- listTags hubUrl (Just (buildInfo buildinfo)) Nothing False
+  return $ mapMaybe (lookupStruct "name") lst
+
+-- | The state of a build
+data BuildState = BuildBuilding
+                | BuildComplete
+                | BuildDeleted
+                | BuildFailed
+                | BuildCanceled
+  deriving (Eq, Enum, Show)
+
+readBuildState :: Value -> BuildState
+readBuildState (ValueInt i) | i `elem` map fromEnum (enumFrom BuildBuilding) = toEnum i
+readBuildState _ = error "invalid build state"
+
+-- | Get the state of a build
+kojiGetBuildState :: String -- ^ hub url
+                  -> BuildInfo
+                  -> IO (Maybe BuildState)
+kojiGetBuildState hubUrl buildinfo =
+  ((fmap readBuildState . lookupStruct "state") =<<) <$>
+  getBuild hubUrl (buildInfo buildinfo)
+
+-- | The state of a task
+data TaskState = TaskFree
+               | TaskOpen
+               | TaskClosed
+               | TaskCanceled
+               | TaskAssigned
+               | TaskFailed
+  deriving (Eq, Enum, Show)
+
+-- | Open task states
+openTaskStates :: [TaskState]
+openTaskStates = [TaskFree, TaskOpen, TaskAssigned]
+
+openTaskValues :: Value
+openTaskValues = ValueArray $ map taskStateToValue openTaskStates
+  where
+    taskStateToValue :: TaskState -> Value
+    taskStateToValue = ValueInt . fromEnum
+
+readTaskState :: Value -> TaskState
+readTaskState (ValueInt i) | i `elem` map fromEnum (enumFrom TaskFree) = toEnum i
+readTaskState _ = error "invalid task state"
+
+getTaskState :: Struct -> Maybe TaskState
+getTaskState st = readTaskState <$> lookup "state" st
+
+-- | Get the state of a taskid
+kojiGetTaskState :: String -- ^ hub url
+                 -> TaskID
+                 -> IO (Maybe TaskState)
+kojiGetTaskState hubUrl tid = do
+  mti <- getTaskInfo hubUrl (getID tid) False
+  return $ case mti of
+             Nothing -> Nothing
+             Just ti -> readTaskState <$> lookupStruct "state" ti
+
+-- | Get info about a task
+kojiGetTaskInfo :: String -- ^ hub url
+                -> TaskID
+                -> IO (Maybe Struct)
+kojiGetTaskInfo hubUrl tid = getTaskInfo hubUrl (getID tid) True
+  -- res <- kojiCall "getTaskInfo" [show taskid]
+  -- let state = res ^? key "state" % _Integer <&> (toEnum . fromInteger)
+  --     arch = res ^? key "arch" % _String
+  -- return $ TaskInfo arch state
+
+-- | Get the children tasks of a task
+kojiGetTaskChildren :: String -- ^ hub url
+                    -> TaskID
+                    -> Bool
+                    -> IO [Struct]
+kojiGetTaskChildren hubUrl tid =
+  getTaskChildren hubUrl (getID tid)
+
+-- | Get the latest build of a package in a tag
+kojiLatestBuild :: String -- ^ hub
+                -> String -- ^ tag
+                -> String -- ^ pkg
+                -> IO (Maybe Struct)
+kojiLatestBuild hubUrl tag pkg =
+  listToMaybe <$> getLatestBuilds hubUrl (InfoString tag) Nothing (Just pkg) Nothing
+
+-- | Get latest build in a tag for package at a time event.
+--
+-- Used for example to implement waitrepo
+kojiLatestBuildRepo :: String -- ^ hub
+                    -> String -- ^ tag
+                    -> Int    -- ^ event
+                    -> String -- ^ pkg
+                    -> IO (Maybe Struct)
+kojiLatestBuildRepo hubUrl tag event pkg =
+  listToMaybe <$> getLatestBuilds hubUrl (InfoString tag) (Just event) (Just pkg) Nothing
+
+-- | Build metadata
+data KojiBuild
+  = KojiBuild
+      { kbBuildId :: Int
+      , kbPackageId :: Int
+      , kbOwnerName :: String
+      , kbNvr :: String
+      }
+  deriving (Show)
+
+-- | List builds in a tag
+kojiListTaggedBuilds :: String -- ^ hub url
+                     -> Bool -- ^ latest
+                     -> String -- ^ tag
+                     -> IO [KojiBuild]
+kojiListTaggedBuilds hubUrl latest tag =
+  mapMaybe readKojiBuild <$> listTagged hubUrl tag Nothing False Nothing latest Nothing Nothing Nothing
+  where
+    readKojiBuild :: Struct -> Maybe KojiBuild
+    readKojiBuild values = do
+      buildId <- lookupStruct "build_id" values
+      packageId <- lookupStruct "package_id" values
+      owner <- lookupStruct "owner_name" values
+      nvr <- lookupStruct "nvr" values
+      return $ KojiBuild buildId packageId owner nvr
+
+-- | Get the build and dest tags for a target.
+kojiBuildTarget :: String -- ^ hubUrl
+                -> String -- ^ target
+                -> IO (Maybe (String, String)) -- ^ (build-tag,dest-tag)
+kojiBuildTarget hub target = do
+  mres <- maybeStruct <$> getBuildTarget hub target
+  case mres of
+    Nothing -> return Nothing
+    Just res -> return $ readTarget res
+  where
+  readTarget res = do
+    buildtag <- lookupStruct "build_tag_name" res
+    desttag <- lookupStruct "dest_tag_name" res
+    return (buildtag, desttag)
+
+-- | List sidetags (preferably for user and/or basetag)
+kojiListSideTags :: String -- ^ hubUrl
+                 -> Maybe String -- ^ basetag
+                 -> Maybe String -- ^ user
+                 -> IO [String] -- ^ list of sidetags
+kojiListSideTags hub mbasetag muser =
+  mapMaybe (lookupStruct "name") . structArray <$> listSideTags hub (InfoString <$> mbasetag) (InfoString <$> muser)
+
+-- | Repo state
+data RepoState = RepoInit
+               | RepoReady
+               | RepoExpired
+               | RepoDeleted
+               | RepoProblem
+  deriving (Eq, Enum, Show)
+
+readRepoState :: Value -> RepoState
+readRepoState (ValueInt i) | i `elem` map fromEnum (enumFrom RepoInit) = toEnum i
+readRepoState _ = error "invalid repo state"
+
+-- getRepoState :: Struct -> Maybe RepoState
+-- getRepoState st = readRepoState <$> lookup "state" st
+
+-- | Get repo info for tag
+kojiGetRepo :: String -- ^ hub url
+            -> String -- ^ tag
+            -> Maybe RepoState
+            -> Maybe Int -- ^ event
+            -> IO (Maybe Struct) -- ^ result
+kojiGetRepo hub tag mstate mevent =
+  maybeStruct <$> getRepo hub tag (fromEnum <$> mstate) mevent False
+
+-- | Get current repo info for tag
+kojiGetCurrentRepo :: String -> String -> IO (Maybe Struct)
+kojiGetCurrentRepo hub tag =
+  maybeStruct <$> getRepo hub tag Nothing Nothing False
diff --git a/src/Distribution/Koji/API.hs b/src/Distribution/Koji/API.hs
new file mode 100644
--- /dev/null
+++ b/src/Distribution/Koji/API.hs
@@ -0,0 +1,840 @@
+{-|
+Low level XMLRPC API based directly on the python API
+since that is the only available reference documentation:
+<https://koji.fedoraproject.org/koji/api>.
+
+Note that many of the procedures in this module are untested and experimental:
+particularly most of those that return a Value.
+
+Higher level wrapper procedures live in Distribution.Koji.
+
+Fixes and enhancements welcome.
+-}
+
+
+
+module Distribution.Koji.API
+       ( Info(..)
+       , koji
+       , hello
+       , checkTagAccess
+       , checkTagPackage
+       , getAPIVersion
+       , getActiveRepos
+       , getAllArches
+       , getAllPerms
+       , getArchive
+       , getArchiveFile
+       , getArchiveType
+       , getArchiveTypes
+       , getAverageBuildDuration
+       , getBuild
+       , getBuildConfig
+       , getBuildLogs
+       , getBuildTarget
+       , getBuildTargets
+       , getBuildType
+       , getBuildroot
+       , getBuildrootListing
+       , getChangelogEntries
+       , getChannel
+       , getEvent
+       , getExternalRepo
+       , getExternalRepoList
+       , getFullInheritance
+       , getGlobalInheritance
+       , getGroupMembers
+       , getHost
+       , getImageArchive
+       , getImageBuild
+       , getInheritanceData
+       , getLastEvent
+       , getLastHostUpdate
+       , getLatestBuilds
+       , getLatestMavenArchives
+       , getLatestRPMS
+       , getMavenArchive
+       , getMavenBuild
+       , getNextRelease
+       , getPackage
+       , getPackageConfig
+       , getPackageID
+       , getRPM
+       , getRPMDeps
+       , getRPMFile
+       , getRPMHeaders
+       , getRepo
+       , getTag
+       , getTagExternalRepos
+       , getTagGroups
+       , getTagID
+       , getTaskChildren
+       , getTaskDescendents
+       , getTaskInfo
+       , getTaskRequest
+       , getTaskResult
+       , getUser
+       , getUserPerms
+       , getVolume
+       , getWinArchive
+       , getWinBuild
+
+       , listArchiveFiles
+       , listArchives
+       , listBTypes
+       , listBuildRPMs
+       , listBuildroots
+       , listBuilds
+       , listCGs
+       , listChannels
+       , listExternalRepos
+       , listHosts
+       , listPackages
+       , listPackagesSimple
+       , listRPMFiles
+       , listRPMs
+       , listSideTags
+       , listTagged
+       , listTaggedArchives
+       , listTaggedRPMS
+       , listTags
+       , listTaskOutput
+       , listTasks
+       , listUsers
+       , listVolumes
+
+       , repoInfo
+       , resubmitTask
+       , tagChangedSinceEvent
+       , tagHistory
+       , taskFinished
+       , taskReport
+
+       , Value(..)
+       , Struct
+       , lookupStruct
+--       , readStructString
+--       , readStructArray
+--       , readMethodParams
+       , maybeStruct
+       , structArray
+       , getValue
+       )
+where
+
+import Data.Maybe
+--import Control.Monad.Fail (MonadFail)
+--import qualified Data.ByteString.Lazy.Char8 as B
+import Network.XmlRpc.Client
+import Network.XmlRpc.Internals
+--import Network.HTTP.Simple
+--import Network.HTTP.Client.Conduit
+import Control.Monad.Except (runExceptT)
+
+-- | Low-level variadic XML RPC call to a Koji Hub
+koji :: Remote a
+     => String -- ^ kojihub url
+     -> String -- ^ command
+     -> a
+koji = remote
+
+-- xmlrpc :: String -> String -> [Value] -> IO Value
+-- xmlrpc url m args = do
+--   initreq <- parseRequest url
+--   let reqbody = renderCall (MethodCall m args)
+--       request = setRequestBody (RequestBodyLBS reqbody) $ setRequestMethod "POST" initreq
+--   resp <- httpLBS request
+--   let respbody = getResponseBody resp
+--   handleError fail $ (parseResponse (B.unpack respbody) >>= handleResponse)
+--   where
+--     -- | Gets the return value from a method response.
+--     --   Throws an exception if the response was a fault.
+--     handleResponse :: MonadFail m => MethodResponse -> m Value
+--     handleResponse (Return v)       = return v
+--     handleResponse (Fault code str) = error ("Error " ++ show code ++ ": " ++ str)
+
+-- FIXME rename to newtype KojiStruct?
+type Struct = [(String,Value)]
+
+maybeString :: Maybe String -> Value
+maybeString = maybe ValueNil ValueString
+
+maybeInt :: Maybe Int -> Value
+maybeInt = maybe ValueNil ValueInt
+
+maybeValue :: Maybe Value -> Value
+maybeValue = fromMaybe ValueNil
+
+-- | info is either an id or string
+data Info = InfoID Int | InfoString String
+
+infoValue :: Info -> Value
+infoValue (InfoID i) = ValueInt i
+infoValue (InfoString s) = ValueString s
+
+maybeInfo :: Maybe Info -> Value
+maybeInfo = maybe ValueNil infoValue
+
+maybeStruct :: Value -> Maybe Struct
+maybeStruct (ValueStruct st) = Just st
+maybeStruct _ = Nothing
+
+structArray :: Value -> [Struct]
+structArray (ValueArray v) = mapMaybe maybeStruct v
+structArray _ = []
+
+-- https://koji.fedoraproject.org/koji/api
+
+-- CG*
+
+-- _listapi()
+
+-- add*
+
+-- applyVolumePolicy(build, strict=False)
+
+-- assignTask(task_id, host, force=False)
+
+-- build(src, target, opts=None, priority=None, channel=None)
+
+-- buildContainer(src, target, opts=None, priority=None, channel='container')
+
+-- buildImage(name, version, arch, target, ksfile, img_type, opts=None, priority=None)
+
+-- buildImageIndirection(opts=None, priority=None)
+
+-- buildImageOz(name, version, arches, target, inst_tree, opts=None, priority=None)
+
+-- buildReferences(build, limit=None, lazy=False)
+
+-- cancelBuild(buildID)
+
+-- cancelTask(task_id, recurse=True)
+
+-- cancelTaskChildren(task_id)
+
+-- cancelTaskFull(task_id, strict=True)
+
+-- chainBuild(srcs, target, opts=None, priority=None, channel=None)
+
+-- chainMaven(builds, target, opts=None, priority=None, channel='maven')
+
+-- changeBuildVolume(build, volume, strict=True)
+
+-- | checkTagAccess(tag_id, user_id=None)
+checkTagAccess :: String -> Int -> Int -> IO Value
+checkTagAccess hubUrl = koji hubUrl "checkTagAccess"
+
+-- | checkTagPackage(tag, pkg)
+checkTagPackage :: String -> Info -> Info -> IO Bool
+checkTagPackage hubUrl taginfo pkginfo = koji hubUrl "checkTagPackage" (infoValue taginfo) (infoValue pkginfo)
+
+-- count*
+
+-- create*
+
+-- debugFunction(name, *args, **kwargs)
+
+-- delete*
+
+-- disable*
+
+-- distRepo(tag, keys, **task_opts)
+
+-- downloadTaskOutput(taskID, fileName, offset=0, size=-1, volume=None)
+
+-- dropGroupMember(group, user)
+
+-- echo(*args)
+
+-- edit*
+
+-- enable*
+
+-- error
+
+-- filterResults(methodName, *args, **kw)
+
+-- findBuildID(X, strict=False)
+
+-- freeTask(task_id)
+
+-- | getAPIVersion()
+getAPIVersion :: String -> IO String
+getAPIVersion hubUrl = koji hubUrl "getAPIVersion"
+
+-- | getActiveRepos()
+getActiveRepos :: String -> IO Value
+getActiveRepos hubUrl = koji hubUrl "getActiveRepos"
+
+-- | getAllArches
+getAllArches :: String -> IO Value
+getAllArches hubUrl = koji hubUrl "getAllArches"
+
+-- | getAllPerms
+getAllPerms :: String -> IO [Struct]
+getAllPerms hubUrl = koji hubUrl "getAllPerms"
+
+-- | getArchive(archive_id, strict=False)
+getArchive :: String -> Int -> IO (Maybe Struct)
+getArchive hubUrl = fmap maybeStruct . koji hubUrl "getArchive"
+
+-- | getArchiveFile(archive_id, filename, strict=False)
+getArchiveFile :: String -> Int -> FilePath -> IO (Maybe Struct)
+getArchiveFile hubUrl archiveID file = maybeStruct <$> koji hubUrl "getArchiveFile" archiveID file
+
+-- | getArchiveType(filename=None, type_name=None, type_id=None, strict=False)
+getArchiveType :: String -> Maybe FilePath -> Maybe String -> Maybe Int -> IO Value
+getArchiveType hubUrl filename type_name type_id =
+  koji hubUrl "getArchiveType" (maybeString filename) (maybeString type_name) (maybeInt type_id)
+
+-- | getArchiveTypes()
+getArchiveTypes :: String -> IO Value
+getArchiveTypes hubUrl = koji hubUrl "getArchiveTypes"
+
+-- | getAverageBuildDuration pkginfo
+getAverageBuildDuration :: String -> Info -> IO Value
+getAverageBuildDuration hubUrl = koji hubUrl "getAverageBuildDuration" . infoValue
+
+-- | getBuild(buildInfo, strict=False)
+getBuild :: String
+         -> Info -- ^ buildID
+         -> IO (Maybe Struct)
+getBuild hubUrl = fmap maybeStruct . koji hubUrl "getBuild" . infoValue
+
+-- | getBuildConfig tag
+getBuildConfig :: String -> String -> IO Value
+getBuildConfig hubUrl = koji hubUrl "getBuildConfig"
+
+-- | getBuildLogs build
+getBuildLogs :: String -> Info -- ^ buildinfo
+             -> IO Value
+getBuildLogs hubUrl = koji hubUrl "getBuildLogs" . infoValue
+
+-- | getBuildTarget info
+getBuildTarget :: String -> String -> IO Value
+getBuildTarget hubUrl = koji hubUrl "getBuildTarget"
+
+-- | getBuildTargets info event buildTagID destTagID
+getBuildTargets :: String -> Maybe Info -> Maybe Int -> Maybe Int -> Maybe Int -> IO Value
+getBuildTargets hubUrl info event buildTagId destTagId  =
+  koji hubUrl "getBuildTargets" (maybeInfo info) (maybeInt event) (maybeInt buildTagId) (maybeInt destTagId)
+
+-- | getBuildType buildinfo
+getBuildType :: String -> Info -- ^ buildinfo
+             -> IO Value
+getBuildType hubUrl = koji hubUrl "getBuildType" . infoValue
+
+-- | getBuildroot buildrootId
+getBuildroot :: String -> Int -> IO Value
+getBuildroot hubUrl = koji hubUrl "getBuildroot"
+
+-- | getBuildrootListing buildrootId
+getBuildrootListing :: String -> Int -> IO Value
+getBuildrootListing hubUrl = koji hubUrl "getBuildrootListing"
+
+-- | getChangelogEntries(buildID=None, taskID=None, filepath=None, author=None, before=None, after=None, queryOpts=None)
+getChangelogEntries :: String
+                    -> Maybe Int -- ^ buildID
+                    -> Maybe Int -- ^ taskID
+                    -> Maybe FilePath
+                    -> Maybe String -- ^ author
+                    -> Maybe String -- ^ before
+                    -> Maybe String -- ^ after
+                    -> IO [Struct]
+getChangelogEntries hubUrl buildID taskID filepath author before after =
+  koji hubUrl "getChangelogEntries" (maybeInt buildID) (maybeInt taskID) (maybeString filepath) (maybeString author) (maybeString before) (maybeString after)
+
+-- | getChannel channelinfo
+getChannel :: String -> Info -> IO Value
+getChannel hubUrl = koji hubUrl "getChannel" . infoValue
+
+-- | getEvent eventid
+getEvent :: String -> Int -> IO Struct
+getEvent hubUrl = koji hubUrl "getEvent"
+
+-- | getExternalRepo info
+getExternalRepo :: String -> Info -> Maybe Int -> IO Struct
+getExternalRepo hubUrl info event =
+  koji hubUrl "getExternalRepo" (infoValue info) () (maybeInt event)
+
+-- | getExternalRepoList(tag_info, event=None)
+getExternalRepoList :: String -> Info -> Maybe Int -> IO [Struct]
+getExternalRepoList hubUrl info event =
+  koji hubUrl "getExternalRepoList" (infoValue info) (maybeInt event)
+
+-- | getFullInheritance(tag, event=None, reverse=False, stops=None, jumps=None)
+getFullInheritance :: String -> String -> Maybe Int -> Bool -> IO Value
+getFullInheritance hubUrl tag event =
+  koji hubUrl "getFullInheritance" tag (maybeInt event)
+
+-- | getGlobalInheritance(event=None)
+getGlobalInheritance :: String -> Maybe Int -> IO Value
+getGlobalInheritance hubUrl = koji hubUrl "getGlobalInheritance" . maybeInt
+
+-- | getGroupMembers(group)
+getGroupMembers :: String -> String -> IO Value
+getGroupMembers hubUrl = koji hubUrl "getGroupMembers"
+
+-- | getHost(hostInfo, strict=False, event=None)
+getHost :: String -> Info -> Maybe Int -> IO Struct
+getHost hubUrl info = koji hubUrl "getHost" (infoValue info) () . maybeInt
+
+-- | getImageArchive(archive_id, strict=False)
+getImageArchive :: String -> Int -> IO Struct
+getImageArchive hubUrl = koji hubUrl "getImageArchive"
+
+-- | getImageBuild(buildInfo, strict=False)
+getImageBuild :: String -> Info -> IO Struct
+getImageBuild hubUrl info = koji hubUrl "getImageBuild" (infoValue info)
+
+-- | getInheritanceData(tag, event=None)
+getInheritanceData :: String -> String -> Maybe Int -> IO Value
+getInheritanceData hubUrl tag event =
+  koji hubUrl "getInheritanceData" tag (maybeInt event)
+
+
+-- | getLastEvent(before=None)
+getLastEvent :: String -> Maybe Int -> IO Value
+getLastEvent hubUrl = koji hubUrl "getLastEvent" . maybeInt
+
+-- | getLastHostUpdate(hostID)
+getLastHostUpdate :: String -> Int -> IO Value
+getLastHostUpdate hubUrl = koji hubUrl "getLastHostUpdate"
+
+-- | getLatestBuilds(tag, event=None, package=None, type=None)
+--
+-- List latest builds for tag (inheritance enabled)
+getLatestBuilds :: String
+                -> Info -- ^ tag
+                -> Maybe Int -- ^ event
+                -> Maybe String -- ^ pkg
+                -> Maybe String -- ^ type
+                -> IO [Struct]
+getLatestBuilds hubUrl tag event pkg type_ =
+  koji hubUrl "getLatestBuilds" (infoValue tag) (maybeInt event) (maybeString pkg) (maybeString type_)
+
+-- | getLatestMavenArchives(tag, event=None, inherit=True)
+getLatestMavenArchives :: String -> String -> Maybe Int -> Bool -> IO Value
+getLatestMavenArchives hubUrl tag event =
+  koji hubUrl "getLatestMavenArchives" tag (maybeInt event)
+
+-- | getLatestRPMS(tag, package=None, arch=None, event=None, rpmsigs=False, type=None)
+getLatestRPMS :: String -> String -> Maybe String -> Maybe String -> Maybe Int -> Bool -> Maybe String -> IO Value
+getLatestRPMS hubUrl tag pkg arch event rpmsigs type_ =
+  koji hubUrl "getLatestRPMS" tag (maybeString pkg) (maybeString arch) (maybeInt event) rpmsigs (maybeString type_)
+
+-- getLoggedInUser()
+
+-- | getMavenArchive(archive_id, strict=False)
+getMavenArchive :: String -> Int -> IO Struct
+getMavenArchive hubUrl = koji hubUrl "getMavenArchive"
+
+-- | getMavenBuild(buildInfo, strict=False)
+getMavenBuild :: String -> Info -> IO Struct
+getMavenBuild hubUrl info = koji hubUrl "getMavenBuild" (infoValue info)
+
+-- | getNextRelease(build_info)
+--
+-- find the last successful or deleted build of this N-V.
+-- If building is specified, skip also builds in progress
+getNextRelease :: String -> Info -> IO Value
+getNextRelease hubUrl info = koji hubUrl "getNextRelease" (infoValue info)
+
+-- | getPackage(info, strict=False, create=False)
+--
+-- Get the id,name for package
+getPackage :: String -> Info -> IO Value
+getPackage hubUrl info = koji hubUrl "getPackage" (infoValue info)
+
+-- | getPackageConfig(tag, pkg, event=None)
+--
+-- Get config for package in tag
+getPackageConfig :: String -> String -> String -> Maybe Int -> IO Value
+getPackageConfig hubUrl tag pkg event =
+  koji hubUrl "getPackageConfig" tag pkg (maybeInt event)
+
+-- | getPackageID(name, strict=False)
+--
+-- Get package ID by name.
+getPackageID :: String -> String -> IO (Maybe Int)
+getPackageID hubUrl pkg = do
+  res <- koji hubUrl "getPackageID" pkg
+  case res of
+    ValueInt i -> return $ Just i
+    _ -> return Nothing
+
+-- | getRPM(rpminfo, strict=False, multi=False)
+getRPM :: String -> Info -> IO Struct
+getRPM hubUrl = koji hubUrl "getRPM" . infoValue
+
+-- | getRPMDeps(rpmID, depType=None, queryOpts=None, strict=False)
+getRPMDeps :: String -> Int -> Maybe String -> IO [Struct]
+getRPMDeps hubUrl rpmid deptype =
+  koji hubUrl "getRPMDeps" rpmid (maybeString deptype)
+
+-- | getRPMFile(rpmID, filename, strict=False)
+getRPMFile :: String -> Int -> FilePath -> IO Struct
+getRPMFile hubUrl = koji hubUrl "getRPMFile"
+
+-- | getRPMHeaders(rpmID=None, taskID=None, filepath=None, headers=None)
+getRPMHeaders :: String -> Maybe Int -> Maybe Int -> Maybe FilePath -> Maybe Value -> IO Struct
+getRPMHeaders hubUrl rpmid taskid file headers =
+  koji hubUrl "getRPMHeaders" (maybeInt rpmid) (maybeInt taskid) (maybeString file) (fromMaybe ValueNil headers)
+
+-- | getRepo(tag, state=None, event=None, dist=False)
+getRepo :: String -> String -> Maybe Int -> Maybe Int -> Bool -> IO Value
+getRepo hubUrl tag state event =
+  koji hubUrl "getRepo" tag (maybeInt state) (maybeInt event)
+
+-- getSessionInfo()
+
+-- | getTag(tagInfo, strict=False, event=None)
+getTag :: String -> Info -> Maybe Int -> IO Struct
+getTag hubUrl info = koji hubUrl "getTag" (infoValue info) () . maybeInt
+
+-- | getTagExternalRepos(tag_info=None, repo_info=None, event=None)
+getTagExternalRepos :: String -> Maybe Info -> Maybe Info -> Maybe Int -> IO Struct
+getTagExternalRepos hubUrl taginfo repoinfo event =
+  koji hubUrl "getTagExternalRepos" (maybeInfo taginfo) (maybeInfo repoinfo) (maybeInt event)
+
+-- | getTagGroups(tag, event=None, inherit=True, incl_pkgs=True, incl_reqs=True, incl_blocked=False)
+getTagGroups :: String -> String -> Maybe Int -> Bool -> Bool -> Bool -> Bool -> IO Value
+getTagGroups hubUrl tag event =
+  koji hubUrl "getTagGroups" tag (maybeInt event)
+
+-- | getTagID(info, strict=False, create=False)
+getTagID :: String -> Info -> IO (Maybe Int)
+getTagID hubUrl tag = do
+  res <- koji hubUrl "getTagID" (infoValue tag)
+  case res of
+    ValueInt i -> return $ Just i
+    _ -> return Nothing
+
+-- | getTaskChildren(task_id, request=False, strict=False)
+getTaskChildren :: String -> Int -> Bool -> IO [Struct]
+getTaskChildren hubUrl = koji hubUrl "getTaskChildren"
+
+-- | getTaskDescendents(task_id, request=False)
+getTaskDescendents :: String -> Int -> Bool -> IO Struct
+getTaskDescendents hubUrl = koji hubUrl "getTaskDescendents"
+
+-- | getTaskInfo(task_id, request=False, strict=False)
+getTaskInfo :: String
+            -> Int
+            -> Bool -- ^ include request details
+            -> IO (Maybe Struct)
+getTaskInfo hubUrl tid request = maybeStruct <$> koji hubUrl "getTaskInfo" tid request
+  -- res <- kojiCall "getTaskInfo" [show taskid]
+  -- let state = res ^? key "state" % _Integer <&> (toEnum . fromInteger)
+  --     arch = res ^? key "arch" % _String
+  -- return $ TaskInfo arch state
+
+-- | getTaskRequest(taskId)
+getTaskRequest :: String -> Int -> IO Value
+getTaskRequest hubUrl = koji hubUrl "getTaskRequest"
+
+-- | getTaskResult(taskId, raise_fault=True)
+getTaskResult :: String -> Int -> IO Value
+getTaskResult hubUrl = koji hubUrl "getTaskResult"
+
+-- | getUser(userInfo=None, strict=False, krb_princs=True)
+getUser :: String -> Info -> Bool -> IO (Maybe Struct)
+getUser hubUrl info krbprncpl =
+  maybeStruct <$> koji hubUrl "getUser" (infoValue info) () krbprncpl
+
+-- | getUserPerms(userID=None)
+getUserPerms :: String -> Maybe Info -> IO Value
+getUserPerms hubUrl = koji hubUrl "getUserPerms" . maybeInfo
+
+-- | getVolume(volume, strict=False)
+getVolume :: String -> Info -> IO Value
+getVolume hubUrl = koji hubUrl "getVolume" . infoValue
+
+-- | getWinArchive(archive_id, strict=False)
+getWinArchive :: String -> Int -> IO Struct
+getWinArchive hubUrl = koji hubUrl "getWinArchive"
+
+-- | getWinBuild(buildInfo, strict=False)
+getWinBuild :: String -> Info -> IO (Maybe Struct)
+getWinBuild hubUrl = fmap maybeStruct . koji hubUrl "getWinBuild" . infoValue
+
+-- grantCGAccess(user, cg, create=False)
+
+-- grantPermission(userinfo, permission, create=False)
+
+-- groupListAdd(taginfo, grpinfo, block=False, force=False, **opts)
+
+-- groupListBlock(taginfo, grpinfo)
+
+-- groupListRemove(taginfo, grpinfo, force=False)
+
+-- groupListUnblock(taginfo, grpinfo)
+
+-- groupPackageListAdd(taginfo, grpinfo, pkg_name, block=False, force=False, **opts)
+
+-- groupPackageListBlock(taginfo, grpinfo, pkg_name)
+
+-- groupPackageListRemove(taginfo, grpinfo, pkg_name, force=False)
+
+-- groupReqListUnblock(taginfo, grpinfo, reqinfo)
+
+-- hasPerm(perm, strict=False)
+
+-- | Say hello to test XMLRPC connection to Koji Hub
+hello :: String -> IO String
+hello hubUrl = koji hubUrl "hello"
+
+-- host.* [skipped]
+
+-- importArchive(filepath, buildinfo, type, typeInfo)
+
+-- importRPM(path, basename)
+
+-- krbLogin(*args, **opts)
+
+-- | listArchiveFiles(archive_id, queryOpts=None, strict=False)
+listArchiveFiles :: String -> Int -> IO [Struct]
+listArchiveFiles hubUrl = koji hubUrl "listArchiveFiles"
+
+-- | listArchives(buildID=None, buildrootID=None, componentBuildrootID=None, hostID=None, type=None, filename=None, size=None, checksum=None, typeInfo=None, queryOpts=None, imageID=None, archiveID=None, strict=False)
+listArchives :: String -> Maybe Int -> Maybe Int -> Maybe Int -> Maybe Int -> Maybe String -> Maybe FilePath -> Maybe Int -> Maybe String -> Maybe Info -> Maybe Int -> Maybe Int -> IO [Struct]
+listArchives hubUrl buildID buildrootID componentBuildrootID hostID type_ file size checksum typeInfo imageID archiveID =
+  koji hubUrl "listArchives" (maybeInt buildID) (maybeInt buildrootID) (maybeInt componentBuildrootID) (maybeInt hostID) (maybeString type_) (maybeString file) (maybeInt size) (maybeString checksum) (maybeInfo typeInfo) () (maybeInt imageID) (maybeInt archiveID)
+
+-- | listBTypes(query=None, queryOpts=None)
+listBTypes :: String -> Value -> IO Value
+listBTypes hubUrl = koji hubUrl "listBTypes"
+
+-- | listBuildRPMs(build)
+listBuildRPMs :: String -> Int -> IO [Struct]
+listBuildRPMs hubUrl = koji hubUrl "listBuildRPMs"
+
+-- | listBuildroots(hostID=None, tagID=None, state=None, rpmID=None, archiveID=None, taskID=None, buildrootID=None, queryOpts=None)
+listBuildroots :: String -> Maybe Int -> Maybe Int -> Maybe Int -> Maybe Int -> Maybe Int -> Maybe Int -> Maybe Int -> IO Value
+listBuildroots hubUrl hostID tagID state rpmID archiveID taskID buildrootID =
+  koji hubUrl "listBuildroots" (maybeInt hostID) (maybeInt tagID) (maybeInt state) (maybeInt rpmID) (maybeInt archiveID) (maybeInt taskID) (maybeInt buildrootID)
+
+-- | listBuilds (packageID=None, userID=None, taskID=None, prefix=None, state=None, volumeID=None, source=None, createdBefore=None, createdAfter=None, completeBefore=None, completeAfter=None, type=None, typeInfo=None, queryOpts=None)
+listBuilds :: String -> Struct -> IO [Struct]
+listBuilds hubUrl args =
+  let maybeArg fld = maybeValue (lookupStruct fld args) in
+    koji hubUrl "listBuilds" (maybeArg "packageID") (maybeArg "userID") (maybeArg "taskID") (maybeArg "prefix") (maybeArg "state") (maybeArg "volumeID") (maybeArg "source") (maybeArg "createdBefore") (maybeArg "createdAfter") (maybeArg "completeBefore") (maybeArg "completeAfter") (maybeArg "type") (maybeArg "typeInfo") (maybeArg "queryOpts")
+
+-- | listCGs()
+listCGs :: String -> IO Struct
+listCGs hubUrl = koji hubUrl "listCGs"
+
+-- | listChannels(hostID=None, event=None)
+listChannels :: String -> Maybe Int -> Maybe Int -> IO Value
+listChannels hubUrl hostID event =
+  koji hubUrl "listChannels" (maybeInt hostID) (maybeInt event)
+
+-- | listExternalRepos(info=None, url=None, event=None, queryOpts=None)
+listExternalRepos :: String -> Maybe Info -> Maybe String -> Maybe Int -> IO Value
+listExternalRepos hubUrl info url event =
+  koji hubUrl "listExternalRepos" (maybeInfo info) (maybeString url) (maybeInt event)
+
+-- | listHosts(arches=None, channelID=None, ready=None, enabled=None, userID=None, queryOpts=None)
+listHosts :: String -> Maybe Value -> Maybe Int -> Bool -> Bool -> Maybe Int -> IO Value
+listHosts hubUrl arches channelID ready enabled userID =
+  koji hubUrl "listHosts" (maybeValue arches) (maybeInt channelID) ready enabled (maybeInt userID)
+
+-- | listPackages(tagID=None, userID=None, pkgID=None, prefix=None, inherited=False, with_dups=False, event=None, queryOpts=None)
+listPackages :: String -> Maybe Int -> Maybe Int -> Maybe Int -> Maybe String -> Bool -> Bool -> Maybe Int -> IO [Struct]
+listPackages hubUrl tagID userID pkgID prefix inherited with_dups event =
+  koji hubUrl "listPackages" (maybeInt tagID) (maybeInt userID) (maybeInt pkgID) (maybeString prefix) inherited with_dups (maybeInt event)
+
+-- | listPackagesSimple prefix
+listPackagesSimple :: String -> String -- ^ package name search prefix
+                   -> IO [Struct]
+listPackagesSimple hubUrl = koji hubUrl "listPackagesSimple"
+
+-- | listRPMFiles(rpmID, queryOpts=None)
+listRPMFiles :: String -> Int -> IO [Struct]
+listRPMFiles hubUrl = koji hubUrl "listRPMFiles"
+
+-- | listRPMs(buildID=None, buildrootID=None, imageID=None, componentBuildrootID=None, hostID=None, arches=None, queryOpts=None)
+listRPMs :: String -> Maybe Int -> Maybe Int -> Maybe Int -> Maybe Int -> Maybe Int -> Maybe Value -> IO [Struct]
+listRPMs hubUrl buildID buildrootID imageID componentBuildrootID hostID arches =
+  koji hubUrl "listRPMs" (maybeInt buildID) (maybeInt buildrootID) (maybeInt imageID) (maybeInt componentBuildrootID) (maybeInt hostID) (maybeValue arches)
+
+-- | listSideTags(basetag=None, user=None, queryOpts=None)
+listSideTags :: String -> Maybe Info -> Maybe Info -> IO Value
+listSideTags hubUrl basetag user = do
+  koji hubUrl "listSideTags" (maybeInfo basetag) (maybeInfo user)
+
+-- | listTagged(tag, event=None, inherit=False, prefix=None, latest=False, package=None, owner=None, type=None)
+listTagged :: String -> String -> Maybe Int -> Bool -> Maybe String -> Bool -> Maybe String -> Maybe String -> Maybe String -> IO [Struct]
+listTagged hubUrl tag event inherit prefix latest package owner type_ =
+  koji hubUrl "listTagged" tag (maybeInt event) inherit (maybeString prefix) latest (maybeString package) (maybeString owner) (maybeString type_)
+
+-- | listTaggedArchives(tag, event=None, inherit=False, latest=False, package=None, type=None)
+listTaggedArchives :: String -> String -> Maybe Int -> Bool -> Bool -> Maybe String -> Maybe String -> IO Value
+listTaggedArchives hubUrl tag event inherit latest package type_ =
+  koji hubUrl "listTaggedArchives" tag (maybeInt event) inherit latest (maybeString package) (maybeString type_)
+
+-- | listTaggedRPMS(tag, event=None, inherit=False, latest=False, package=None, arch=None, rpmsigs=False, owner=None, type=None)
+listTaggedRPMS :: String -> String -> Maybe Int -> Bool -> Bool -> Maybe String ->  Maybe String -> Bool -> Maybe String -> Maybe String -> IO Value
+listTaggedRPMS hubUrl tag event inherit latest package arch rpmsigs owner type_ =
+  koji hubUrl "listTaggedRPMS" tag (maybeInt event) inherit latest (maybeString package) (maybeString arch) rpmsigs (maybeString owner) (maybeString type_)
+
+-- | listTags(build=None, package=None, perms=True, queryOpts=None)
+listTags :: String -> Maybe Info -> Maybe Info -> Bool -> IO [Struct]
+listTags hubUrl build package =
+  koji hubUrl "listTags" (maybeInfo build) (maybeInfo package)
+
+-- | listTaskOutput(taskID, stat=False, all_volumes=False, strict=False)
+listTaskOutput :: String -> Int -> Bool -> Bool -> Bool -> IO Struct
+listTaskOutput hubUrl = koji hubUrl "listTaskOutput"
+
+-- | listTasks(opts=None, queryOpts=None)
+listTasks :: String -> Struct -- ^ opts
+          -> Struct -- ^ qopts
+          -> IO [Struct]
+listTasks hubUrl = koji hubUrl "listTasks"
+
+-- | listUsers(userType=0, prefix=None, queryOpts=None)
+listUsers :: String -> Maybe Int -> Maybe String -> IO [Struct]
+listUsers hubUrl userType prefix =
+  koji hubUrl "listUsers" (maybeInt userType) (maybeString prefix)
+
+-- | listVolumes()
+listVolumes :: String -> IO Value
+listVolumes hubUrl = koji hubUrl "listVolumes"
+
+-- login(*args, **opts)
+
+-- logout()
+
+-- logoutChild(session_id)
+
+-- makeTask(*args, **opts)
+
+-- mavenBuild(url, target, opts=None, priority=None, channel='maven')
+
+-- mavenEnabled()
+
+-- mergeScratch(task_id)
+
+-- moveAllBuilds(tag1, tag2, package, force=False)
+
+-- moveBuild(tag1, tag2, build, force=False)
+
+-- newGroup(name)
+
+-- newRepo(tag, event=None, src=False, debuginfo=False, separate_src=False)
+
+-- packageListAdd(taginfo, pkginfo, owner=None, block=None, extra_arches=None, force=False, update=False)
+
+-- packageListBlock(taginfo, pkginfo, force=False)
+
+-- packageListRemove(taginfo, pkginfo, force=False)
+
+-- packageListSetArches(taginfo, pkginfo, arches, force=False)
+
+-- packageListSetOwner(taginfo, pkginfo, owner, force=False)
+
+-- packageListUnblock(taginfo, pkginfo, force=False)
+
+-- queryHistory(tables=None, **kwargs)
+
+-- queryRPMSigs(rpm_id=None, sigkey=None, queryOpts=None)
+
+-- remove*
+
+-- repo*
+
+-- | repoInfo(repo_id, strict=False)
+repoInfo :: String -> Int -> IO Value
+repoInfo hubUrl = koji hubUrl "repoInfo"
+
+-- resetBuild(build)
+
+-- restartHosts(priority=5, options=None)
+
+-- | resubmitTask(taskID)
+resubmitTask :: String -> Int -> IO Value
+resubmitTask hubUrl = koji hubUrl "resubmitTask"
+
+-- revoke*
+
+-- runroot(tagInfo, arch, command, channel=None, **opts)
+
+-- search(terms, type, matchType, queryOpts=None)
+
+-- set*
+
+-- sharedSession()
+
+-- showOpts()
+
+-- showSession()
+
+-- sslLogin(*args, **opts)
+
+-- subsession()
+
+-- system.*
+
+-- tagBuild(tag, build, force=False, fromtag=None)
+
+-- tagBuildBypass(tag, build, force=False, notify=True)
+
+-- | tagChangedSinceEvent(event, taglist)
+tagChangedSinceEvent :: String -> Int -> Value -> IO Bool
+tagChangedSinceEvent hubUrl = koji hubUrl "tagChangedSinceEvent"
+
+-- | tagHistory(build=None, tag=None, package=None, active=None, queryOpts=None)
+tagHistory :: String -> Maybe Info -> Maybe Info -> Maybe Info -> Bool -> IO Value
+tagHistory hubUrl build tag package =
+  koji hubUrl "tagHistory" (maybeInfo build) (maybeInfo tag) (maybeInfo package)
+
+-- | taskFinished(taskId)
+taskFinished :: String -> Int -> IO Bool
+taskFinished hubUrl = koji hubUrl "taskFinished"
+
+-- | taskReport(owner=None)
+taskReport :: String -> Maybe String -> IO Value
+taskReport hubUrl = koji hubUrl "taskReport" . maybeString
+
+-- untag*
+
+-- updateNotification(id, package_id, tag_id, success_only)
+
+-- uploadFile(path, name, size, md5sum, offset, data, volume=None)
+
+-- winBuild(vm, url, target, opts=None, priority=None, channel='vm')
+
+-- winEnabled()
+
+-- wrapperRPM(build, url, target, priority=None, channel='maven', opts=None)
+
+-- writeSignedRPM(an_rpm, sigkey, force=False)
+
+
+-- readStructString :: String -> Struct -> String
+-- readStructString key str =
+--   case lookup key str of
+--     Just (ValueString s) -> s
+--     _ -> error $ "No String for " ++ key
+
+-- readStructArray :: String -> Struct -> Maybe [Value]
+-- readStructArray key struct =
+--   either error id <$> runExceptT (getField key struct)
+-- --    Just (ValueArray s) -> s
+-- --    _ -> error $ "No Array for " ++ key
+
+-- readMethodParams :: String -> Maybe [Value]
+-- readMethodParams s =
+--   either error params <$> runExceptT (parseCall s)
+--   where
+--     params (MethodCall _m str) = str
+
+-- | Lookup a key in a XML result
+lookupStruct :: XmlRpcType a => String -> Struct -> Maybe a
+lookupStruct key struct =
+  either error id <$> runExceptT (getField key struct)
+
+getValue :: XmlRpcType a => Value -> Maybe a
+getValue = fmap (either error id) . runExceptT . fromValue
