NetSNMP 0.1.0 → 0.1.1
raw patch · 2 files changed
+29/−25 lines, 2 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
Files
- NetSNMP.cabal +2/−2
- src/Network/Protocol/NetSNMP.hsc +27/−23
NetSNMP.cabal view
@@ -1,6 +1,6 @@ Name: NetSNMP-Version: 0.1.0+Version: 0.1.1 Synopsis: Bindings for net-snmp's C API for clients Description: Network.Protocol.NetSNMP is a partial binding to the library portion of the net-snmp package. It uses the@@ -22,7 +22,7 @@ library hs-source-dirs: src- build-depends: base+ build-depends: base >=4 && <5 build-tools: hsc2hs exposed-modules: Network.Protocol.NetSNMP extensions: ForeignFunctionInterface, CPP, EmptyDataDecls
src/Network/Protocol/NetSNMP.hsc view
@@ -136,7 +136,7 @@ -- |An SNMP value together with its OID. Returned by the query -- routines 'snmpGet', 'snmpNext', and 'snmpWalk'. data SnmpResult = SnmpResult {- oid :: String, -- ^Dotted-decimal ObjectId of the value+ oid :: String, -- ^Dotted-decimal ObjectId of the value value :: ASNValue -- ^Typed representation of the value } deriving (Eq, Show) @@ -300,12 +300,10 @@ -> Community -- ^SNMP community (password) -> String -- ^OID to be queried -> IO (Either String SnmpResult)-snmpGet version hostname community oid = runTrouble $ do- session <- readyCommunitySession version hostname community- let get = mkSnmpGet snmp_msg_get session- result <- get oid- closeSession session- return result+snmpGet version hostname community oid = runTrouble $ bracketT+ (readyCommunitySession version hostname community) -- session+ closeSession+ (flip (mkSnmpGet snmp_msg_get) oid) -- |Simple community-authenticated SNMP getnext. Returns the first object -- after the OID queried, or a descriptive error message.@@ -322,12 +320,10 @@ -> Community -- ^SNMP community (password) -> String -- ^OID to be queried -> IO (Either String SnmpResult)-snmpNext version hostname community oid = runTrouble $ do- session <- readyCommunitySession version hostname community- let next = mkSnmpGet snmp_msg_getnext session- result <- next oid- closeSession session- return result+snmpNext version hostname community oid = runTrouble $ bracketT+ (readyCommunitySession version hostname community) -- session+ closeSession+ (flip (mkSnmpGet snmp_msg_getnext) oid) -- |Simple community-authenticated SNMP walk. Returns a list of objects, -- starting with the object after the OID queried, and continuing@@ -349,21 +345,18 @@ -> Community -- ^SNMP community (password) -> String -- ^OID to be queried -> IO (Either String [SnmpResult])-snmpWalk version hostname community walkoid = runTrouble $ do- session <- readyCommunitySession version hostname community- let next = mkSnmpGet snmp_msg_getnext session- result <- go next walkoid- closeSession session- return result+snmpWalk version hostname community walkoid = runTrouble $ bracketT+ (readyCommunitySession version hostname community) -- session+ closeSession+ (go walkoid . mkSnmpGet snmp_msg_getnext) where- go :: (String -> Trouble SnmpResult) -> String -> Trouble [SnmpResult]- -- go next oid = flip catchT (const $ return []) $ do- go next oid = do+ go :: String -> (String -> Trouble SnmpResult) -> Trouble [SnmpResult]+ go oid next = do v@(SnmpResult nextoid val) <- next oid case () of _ | nextoid == oid -> return [] -- throwT "end of mib" -- return [] | walkoid `isPrefixOf` nextoid -> do- vs <- go next nextoid+ vs <- go nextoid next return (v:vs) | otherwise -> return [] -- throwT "end of walk" -- return [] @@ -824,6 +817,17 @@ r <- runTrouble m case r of (Left s) -> runTrouble (h s) (Right v) -> return r++handleT :: (String -> Trouble a) -> Trouble a -> Trouble a+handleT = flip catchT++bracketT :: Trouble a -> (a -> Trouble b) -> (a -> Trouble c) -> Trouble c+bracketT before after thing = do+ a <- before+ handleT (\s -> after a >> throwT s) $ do+ result <- thing a+ after a+ return result -- Routines to 'hoist' anything with IO return type into the -- equivalent with (Trouble a) ie. IO (Either String a) return type.